簡體   English   中英

從 WooCommerce“暫停訂單”和“新訂單”電子郵件中刪除訂單編號

[英]Remove Order # from WooCommerce “Order on-hold” & “New Order” Emails

我想從 WooCommerce 生成的“訂單暫停”和“新訂單”電子郵件中刪除自動生成的訂單號。

我正在使用第三方插件在下訂單后分配自定義訂單號,因此重要的是我分配的新訂單號仍然可以在以后的電子郵件中使用。 我不希望客戶(或管理員)在更改之前看到原始訂單號。

任何幫助將不勝感激!

更新(僅適用於 woocommerce 3.3+ 特定模板)

您將需要通過您的子主題覆蓋 Woocommerce 電子郵件模板,如以下鏈接的官方文檔中所述:

模板結構和通過主題覆蓋模板

要復制和覆蓋的模板是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)新訂單(管理員):

在此處輸入圖片說明

2) 客戶暫停訂單:

在此處輸入圖片說明

現在,您還需要在 WooCommerce > 設置 > 電子郵件中從“新訂單”主題中刪除({order_number})並保存...

在此處輸入圖片說明

你完成了…

通過 CSS 刪除訂單號

如果您不想覆蓋電子郵件模板,您可以使用woocommerce_email_styles鈎子添加一個簡單的 CSS 規則來隱藏 WooCommerce 電子郵件中的訂單號。

這個鈎子在模板加載后立即激活: /woocommerce/emails/email-styles.php

要僅隱藏“Order on-hold”和“New Order”模板的訂單號,您可以使用 woocommerce_email_styles 鈎子的第二個 $ email 參數來檢查 ID。 在此處查找列表:使用 Woocommerce 中的電子郵件 ID 定位特定電子郵件

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

添加新訂單號

根據此答案,您還可以添加新訂單號,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM