从WooCommerce中删除订单#"暂停订单" &安培; "新订单"电子邮件

时间:2018-05-07 23:56:53

标签: php wordpress templates woocommerce email-notifications

我想从"订单暂停"中删除自动生成的订单号。和"新订单" WooCommerce生成的电子邮件。

我在下订单后使用第三方插件分配自定义订单号,因此我分配的新订单号仍可用于将来的电子邮件,这一点非常重要。我不希望客户(或管理员)看到原始订单号,直到更改为止。

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

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

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

Template structure & Overriding templates via a theme

要复制和覆盖的模板是woocommerce/templates/emails/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>

为:

<?php
    // Targetting specific email notificatoins
    $email_ids = array('new_order', 'customer_on_hold_order');

    $date = sprintf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) );

    // Displaying order number except for "New Order" and "Customer On Hold Order" notifications
    if( ! in_array($email->id, $email_ids) ){
        $order_number = sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() );
        $date = '('.$date.')';
    } else {
        $date = __('Order date:', 'woocommerce') . ' ' . $date;
        $order_number = '';
    }

    if ( $sent_to_admin ) {
        $before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
        $after  = '</a> ';
    } else {
        $before = '';
        $after  = ' ';
    }
?>

<h2><?php echo $before . $order_number . $after . $date; ?></h2>

这将删除“新订单”和“客户保留订单”电子邮件通知中的订单号。你会得到:

1)新订单(管理员):

enter image description here

2)客户暂停订单:

enter image description here

现在你还需要在WooCommerce&gt;设置&gt;通过电子邮件从“新订单”主题中删除({order_number})并保存...

enter image description here

你完成了......

答案 1 :(得分:0)

通过 CSS 删除订单号

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

这个钩子在模板加载后立即激活:/woocommerce/emails/email-styles.php

<块引用>

仅隐藏“Order on-hold”和“New Order”的订单号 模板您可以使用第二个 $ email 参数 woocommerce_email_styles 钩子来检查 id。在此处查找列表:Targeting specific email with the email id in Woocommerce

// 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;
}

代码已经过测试并且可以工作。将它添加到您的活动主题的functions.php。

添加新订单号

基于this answer,您还可以添加新订单号,如下所示:

// 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
    }
}

代码已经过测试并且可以工作。将它添加到您的活动主题的functions.php。

相关问题