WooCommerce为某些产品手动触发新订单电子邮件
请将此代码作为WooCommerce新订单电子邮件手动触发的解决方案,用于某些产品,但我不知道将此代码放入WooCommerce为某些产品手动触发新订单电子邮件,woocommerce,Woocommerce,请将此代码作为WooCommerce新订单电子邮件手动触发的解决方案,用于某些产品,但我不知道将此代码放入functions.php或其他位置,谢谢 /** * Modified from https://www.skyverge.com/blog/add-woocommerce-email-recipients-conditionally/ * * Add another email recipient for admin New Order emails if a product f
functions.php
或其他位置,谢谢
/**
* Modified from https://www.skyverge.com/blog/add-woocommerce-email-recipients-conditionally/
*
* Add another email recipient for admin New Order emails if a product from a specific category or with a specific tag is ordered
*
* @param string $recipient a comma-separated string of email recipients (will turn into an array after this filter!)
* @param \WC_Order $order the order object for which the email is sent
* @return string $recipient the updated list of email recipients
*/
function sv_conditional_email_recipient( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
// Not sure why this is even a thing, but shikata ga nai
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
if ( 'wc-settings' === $page ) {
return $recipient;
}
// just in case
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
$items = $order->get_items();
// check if product from category or with tag is in order
foreach ( $items as $item ) {
$product = $order->get_product_from_item( $item );
$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names');
$product_cats = wp_get_post_terms( $product->get_id, 'product_cat', $args ); // could swap product_cat for product_tag
// add our extra recipient if there's a product from the category with slug "dieta" - commas needed!
// we can bail if we've found one, no need to add the recipient more than once
if ( $product && in_array( "dieta", $product_cats ) ) {
$recipient .= ', notify@example.com';
return $recipient;
}
}
return $recipient;
}
add_filter( 'woocommerce_email_recipient_new_order', 'sv_conditional_email_recipient', 10, 2 );
我对这一个进行了编码,它可以在我的网站上运行,不要忘记用类别名称和
首先替换猫的名称_email@domain.com,第二_email@domain.com
通过这两封电子邮件
function change_email_recipient_depending_of_cat ( $recipient, $order ) {
global $woocommerce;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
if ( has_term( 'the_name_of_the_cat', 'product_cat', $product_id ) ) {
$recipient = 'first_email@domain.com,second_email@domain.com';
}
return $recipient;
}
}
add_filter( 'woocommerce_email_recipient_new_order', 'change_email_recipient_depending_of_cat', 10, 2 );
你可以把它放在function.php的末尾,记得删除
HI Jerome谢谢你的回复我添加了它但我总是无法收到新订单的电子邮件手动触发某些产品你有什么解决方法吗?谢谢你能收到这个网站的自动电子邮件通知吗?是的,我收到了@jeromeMIt不清楚你在问什么。您的问题似乎可以手动触发电子邮件,但您的代码是关于将收件人添加到电子邮件中。