【发布时间】:2022-12-13 00:47:57
【问题描述】:
我希望如果购物车中有特定商品(通过 id),则只将通知电子邮件发送给管理员而不发送给客户
是否有允许我这样做的 sn-p?
谢谢
【问题讨论】:
-
你能用我的回答解决问题吗?
标签: wordpress function woocommerce hook-woocommerce
我希望如果购物车中有特定商品(通过 id),则只将通知电子邮件发送给管理员而不发送给客户
是否有允许我这样做的 sn-p?
谢谢
【问题讨论】:
标签: wordpress function woocommerce hook-woocommerce
在主题的 functions.php 文件中使用以下代码。不要忘记用您自己的电子邮件替换电子邮件。
add_action( 'woocommerce_add_to_cart', 'cwpai_woo_send_email_to_admin_on_add_to_cart', 10, 6 );
function cwpai_woo_send_email_to_admin_on_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
$product = wc_get_product( $product_id );
$product_name = $product->get_name();
$user = wp_get_current_user();
$user_name = $user->user_login;
$time = date( 'Y-m-d H:i:s' );
$message = sprintf(
'%s was added to the cart by %s at %s',
$product_name,
$user_name,
$time
);
wp_mail( 'admin@example.com', 'Product added to cart', $message );
}
【讨论】: