按照此代码示例,禁用特定产品的WooCommerce电子邮件通知 (我目前无法在此处发表评论)。我实现了为孤立的产品运行的代码,这意味着仅当该产品位于order ($product_id == 5274
)时,此代码才有效:
add_filter('woocommerce_email_recipient_new_order', 'remove_free_course_notifications', 10, 2);
function remove_free_course_notifications( $recipient, $order )
{
$page = $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : '';
if ('wc-settings' === $page) {
return $recipient;
}
if (!$order instanceof WC_Order) {
return $recipient;
}
//my product id is 5274
$items = $order->get_items();
foreach ($items as $item) {
$product_id = $item['product_id'];
if ($product_id == 5274) {
$recipient = '';
}
return $recipient;
}
}
但是,如果一个订单同时具有其他商品(产品),则不会发送任何通知给管理员。
请您让我知道如何更改此代码以发送订单中包含的其余商品的管理员通知吗?
此代码已过时。请改用以下内容,以停止针对“专有”定义产品的新订单管理员通知:
add_filter( 'woocommerce_email_recipient_new_order', 'remove_free_course_notifications', 10, 2 );
function remove_free_course_notifications( $recipient, $order )
{
if ( ! is_a( $order, 'WC_Order' ) ) {
return $recipient;
}
$targeted_product_id = 5274; // Here set your product ID
$other_found = $product_found = false;
foreach ( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
if ( $item->get_product_id() == $targeted_product_id ) {
$product_found = true;
} else {
$other_found = true;
}
}
if ( $product_found && ! $other_found ) {
return '';
}
return $recipient;
}
代码进入活动子主题(或活动主题)的functions.php文件中。它应该工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句