【问题标题】:Woocommerce Send only email admin if specific product is on the cart如果特定产品在购物车中,Woocommerce 仅发送电子邮件管理员
【发布时间】:2022-12-13 00:47:57
【问题描述】:

我希望如果购物车中有特定商品(通过 id),则只将通知电子邮件发送给管理员而不发送给客户

是否有允许我这样做的 sn-p?

谢谢

【问题讨论】:

  • 你能用我的回答解决问题吗?

标签: wordpress function woocommerce hook-woocommerce


【解决方案1】:

在主题的 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 );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多