【问题标题】:Display a custom text based on product category in WooCommerce Email在 WooCommerce 电子邮件中根据产品类别显示自定义文本
【发布时间】:2018-11-07 03:24:05
【问题描述】:

我正在尝试在“订单完成”电子邮件中显示一些“有条件的”自定义文本,当订单被标记为完成时发送给客户。我用过the following code

现在,我想让这段代码有条件,所以这段代码应该只对“礼品”类别的产品有效。我找不到任何适合此特定功能的 Woocommerce 功能。

任何帮助将不胜感激。

这是我现在拥有的:

add_action( 'woocommerce_email_before_order_table', 
'bbloomer_add_content_specific_email', 20, 4 );

function bbloomer_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id == 'customer_completed_order' ) {
        echo '<p class="email-text-conditional">Thank you for your order with Adventure Clues, we have sent your recipient the gift card’</p>';
    }
}

【问题讨论】:

    标签: php wordpress woocommerce custom-taxonomy email-notifications


    【解决方案1】:

    尝试以下方法:

    add_action( 'woocommerce_email_before_order_table', 'email_before_order_table_conditional_display', 20, 4 );
    function email_before_order_table_conditional_display( $order, $sent_to_admin, $plain_text, $email ) {
        // Only for "commpeted" order status notification
        if ( 'customer_completed_order' !== $email->id ) return;
    
        foreach( $order->get_items() as $item ){
            if( has_term( "Gifts", "product_cat", $item->get_product_id() ) ){
                echo '<p class="email-text-conditional">Thank you for your order with Adventure Clues, we have sent your recipient the gift card.</p>';
                break;
            }
            if( has_term( "Clothes", "product_cat", $item->get_product_id() ) ){
                echo '<p class="email-text-conditional">Thank you for your order with Adventure Clues, we are managing your Clothes.</p>';
                break;
            }
        }
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 2020-12-07
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2019-06-26
      • 2020-12-29
      • 2021-02-10
      • 2021-03-22
      相关资源
      最近更新 更多