【发布时间】:2018-07-02 16:37:41
【问题描述】:
我正在尝试禁用或更改发送给管理员的 woocommerce 确认电子邮件的主题行。
我只想为一个特定的产品类别执行此操作。
感谢任何帮助。
【问题讨论】:
标签: php wordpress woocommerce categories email-notifications
我正在尝试禁用或更改发送给管理员的 woocommerce 确认电子邮件的主题行。
我只想为一个特定的产品类别执行此操作。
感谢任何帮助。
【问题讨论】:
标签: php wordpress woocommerce categories email-notifications
更新 (与您的评论相关)。
使用挂在woocommerce_email_subject_new_order 过滤器挂钩中的自定义函数将允许您更改特定产品类别的“新订单”管理员电子邮件通知的主题。
您必须在目标产品类别和自定义主题下方的代码中定义:
add_filter( 'woocommerce_email_subject_new_order', 'custom_subject_for_new_order', 10, 2 );
function custom_subject_for_new_order( $subject, $order ) {
$found = $others = false;
// HERE define your product categories in the array (can be IDs Slugs or Names)
$categories = array('clothing'); // coma separated for multiples categories
// HERE define your custom subject for those defined product categories
$custom_subject = __("My custom subject goes here", "woocommerce");
// Loop through order items
foreach( $order->get_items() as $item ){
if( has_term( $categories, 'product_cat', $item->get_product_id() ) && $found )
$found = true; // Category is found
else
$others = true; // Other Categories are found
}
// Return the custom subject when targeted product category is found but not others.
return $found && ! $others ? $custom_subject : $subject;
}
代码进入活动子主题(或活动主题)的function.php文件中。
经过测试并且有效。
【讨论】: