【问题标题】:Woocommerce Custom EmailWoocommerce 自定义电子邮件
【发布时间】:2018-11-03 02:59:39
【问题描述】:

我需要有关 woocommerce 自定义电子邮件挂钩的帮助。

每当产品完成时,我都会尝试根据产品 ID 发送不同的电子邮件。

我的代码不起作用,如下:

/**************
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' );
  }
}  
}

非常感谢任何建议

【问题讨论】:

  • 欢迎来到 SO。在寻求帮助时,重要的是不仅要说“这不起作用”,还要解释您的预期结果是什么以及您的代码产生的结果与此有何不同。请阅读stackoverflow.com/help/how-to-ask
  • 你说的产品已经完成是什么意思?你的意思是订单完成了吗?
  • @Nick(这对 SO 有效吗?)感谢您的建议。下次我将在我的问题陈述中更具描述性。感谢您的耐心等待。
  • @melvin 在重新阅读我的问题后,你是对的 - 这没有意义。不过你确实猜到了,我的意思是订单完成时。

标签: php wordpress woocommerce orders email-notifications


【解决方案1】:

您的代码中存在一些错误,请尝试以下操作

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

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

【讨论】:

  • 非常感谢您的帮助。这正是我一直在寻找的,而且效果很好。您没有看到的是 5 个小时的尝试和重试这个钩子,但在向 SO 致敬之前没有成功,所以再次感谢。我确实有最后一个问题......如果我想添加其他产品,我可以复制并粘贴最后一个“elseif”语句并相应地更改产品ID,对吗?
猜你喜欢
  • 2018-01-20
  • 2020-08-31
  • 2016-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-19
  • 2018-01-07
  • 2019-04-25
相关资源
最近更新 更多