douyou7797 2018-05-28 13:51
浏览 24
已采纳

在WooCommerce电子邮件中显示基于产品类别的自定义文本

I'm trying to display some "conditional" custom text on the "Order Complete" email, which is sent to the customers when an order is marked as completed. I have used the following code.

Now, I want to make this code conditional, so this code should only be active for the "Gift" Category products. I couldn't find any appropriate Woocommerce functions for this particular functionality.

Any help would be appreciated.

This is what I have for now:

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>';
    }
}
  • 写回答

1条回答 默认 最新

  • dpqjvoq9033 2018-05-28 14:35
    关注

    Try the following:

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

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题