简体   繁体   English

Woocommerce自定义电子邮件

[英]Woocommerce Custom Email

I need help with a custom email hook for woocommerce. 我需要有关woocommerce的自定义电子邮件挂钩的帮助。

I am trying to send a different email depending on product ID whenever a product is completed. 每当产品完成时,我都尝试根据产品ID发送不同的电子邮件。

My code, which is not working, is as follows: 我的代码不起作用,如下所示:

/**************
DIFFERENT MESSAGES FOR DIFFERENT PRODUCTS
****************/

//hook our function to the new order email
add_action('woocommerce_email_order_details',     'uiwc_email_order_details_products', 1, 4);

function uiwc_email_order_details_products($order, $admin, $plain, $email) {
 $status = $order->get_status();

 // checking if it's the order status we want
  if ( $status == "completed" ) {
   $items = $order->get_items();

    if ( $item['product_id'] == "3181") {
      echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https:XXXXX">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes.  After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', 'uiwc' );
  }

   elseif ( $item['product_id'] == "3223") {
      echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', 'uiwc' );
  }
}  
}

Any suggestions is greatly appreciated 任何建议,不胜感激

There is some mistakes in your code, instead try the following 您的代码中有一些错误,请尝试以下操作

//hook our function to the new order email
add_action( 'woocommerce_email_order_details', 'custom_email_order_details', 4, 4 );
function custom_email_order_details( $order, $admin, $plain, $email ) {
    $domain = 'woocommerce';

    // checking if it's the order status we want
    if ( $order->has_status('completed') ) {
        foreach( $order->get_items() as $item ){
            if ( $item->get_product_id() == '3181' ) {
                echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https://xxxxxx">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes. After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', $domain );
                break;
            }
            elseif ( $item->get_product_id() == '3223' ) {
                echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', $domain );
                break;
            }
        } 
    }  
}

Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM