Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除“来自WooCommerce”的订单;“暂停订单”&&引用;“新订单”;电子邮件_Php_Wordpress_Templates_Woocommerce_Email Notifications - Fatal编程技术网

Php 删除“来自WooCommerce”的订单;“暂停订单”&&引用;“新订单”;电子邮件

Php 删除“来自WooCommerce”的订单;“暂停订单”&&引用;“新订单”;电子邮件,php,wordpress,templates,woocommerce,email-notifications,Php,Wordpress,Templates,Woocommerce,Email Notifications,我想从WooCommerce生成的“订单保留”和“新订单”电子邮件中删除自动生成的订单号 我正在使用第三方插件在下单后分配自定义订单号,因此我分配的新订单号仍然可以在未来的电子邮件中使用,这一点很重要。我不想让客户(或管理员)看到原始订单号,直到它被更改 任何帮助都将不胜感激 已更新(仅适用于woocommerce 3.3+特定模板) 您需要通过您的子主题覆盖Woocommerce电子邮件模板,如以下链接的官方文档所述: 要复制和覆盖的模板是woocommerce/templates/emai

我想从WooCommerce生成的“订单保留”和“新订单”电子邮件中删除自动生成的订单号

我正在使用第三方插件在下单后分配自定义订单号,因此我分配的新订单号仍然可以在未来的电子邮件中使用,这一点很重要。我不想让客户(或管理员)看到原始订单号,直到它被更改

任何帮助都将不胜感激

已更新(仅适用于woocommerce 3.3+特定模板)

您需要通过您的子主题覆盖Woocommerce电子邮件模板,如以下链接的官方文档所述:

要复制和覆盖的模板是
woocommerce/templates/email/email order details.php

在此模板中(复制到您的主题中,如前所述),您需要更改整个块:

<h2>
    <?php
    if ( $sent_to_admin ) {
        $before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
        $after  = '</a>';
    } else {
        $before = '';
        $after  = '';
    }
    /* translators: %s: Order ID. */
    echo wp_kses_post( $before . sprintf( __( 'Order #%s', 'woocommerce' ) . $after . ' (<time datetime="%s">%s</time>)', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) );
    ?>
</h2>


通过CSS删除订单号

如果你不想覆盖电子邮件模板,你可以使用钩子添加一个简单的CSS规则,隐藏电子邮件中的订单号

这个钩子在模板加载后被激活:
/woocommerce/email/email styles.php

仅为“保留订单”和“新订单”隐藏订单号 模板您可以使用 woocommerce\u email\u styles钩子检查id。请在此处查找列表:

该代码已经过测试,可以正常工作。将其添加到活动主题的functions.php中

添加新订单号

根据需要,您还可以添加新订单号,如下所示:

// adds the new order number before the order table in the completed order email
add_action( 'woocommerce_email_before_order_table', 'add_content_before_order_table', 99, 4 );
function add_content_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
    // define the ids of the emails for which you want to add CSS rules
    $email_ids = array(
        'new_order',
        'customer_on_hold_order'
    );
    // adds CSS rules to these emails only
    if ( in_array( $email->id, $email_ids ) ) {
        echo '<p>New order number</p>'; // do not use the <h2> tag otherwise it will be hidden
    }
}
//在已完成的订单电子邮件中的订单表之前添加新订单号
添加操作('WOOMerce\u email\u在订单表之前','add\u content\u在订单表之前',99,4);
函数将内容添加到订单表格之前($order,$sent,$to,$admin,$plain,$email){
//定义要为其添加CSS规则的电子邮件的ID
$email\u id=数组(
“新秩序”,
“客户保留订单”
);
//仅向这些电子邮件添加CSS规则
if(在数组中($email->id,$email\u id)){
echo“新订单号”

;//不要使用该标记,否则它将被隐藏 } }

该代码已经过测试,可以正常工作。将其添加到活动主题的functions.php中。

首先,感谢您的快速响应!但是,我没有在模板文件中看到您引用的第一块代码。我看到一个类似的块包装在一个中,但是用您提供的代码替换它似乎不起作用。我错过什么了吗?我在一个多站点网络上,但我不认为这会有什么不同。@RBaum我已经更新了代码,现在它将匹配……很抱歉,我没有获得正确的模板,该模板已随woocommerce 3.3更改。
// hides the order number in the email templates
add_filter( 'woocommerce_email_styles', 'add_woocommerce_email_styles', 10, 2 );
function add_woocommerce_email_styles( $css, $email ) {
    // define the ids of the emails for which you want to add CSS rules
    $email_ids = array(
        'new_order',
        'customer_on_hold_order'
    );
    // adds CSS rules to these emails only
    if ( in_array( $email->id, $email_ids ) ) {
        $css .= 'div[id^="body_content_inner"] > h2 { display: none; }';
    }
    return $css;
}
// adds the new order number before the order table in the completed order email
add_action( 'woocommerce_email_before_order_table', 'add_content_before_order_table', 99, 4 );
function add_content_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
    // define the ids of the emails for which you want to add CSS rules
    $email_ids = array(
        'new_order',
        'customer_on_hold_order'
    );
    // adds CSS rules to these emails only
    if ( in_array( $email->id, $email_ids ) ) {
        echo '<p>New order number</p>'; // do not use the <h2> tag otherwise it will be hidden
    }
}