• Resolved pierre

    (@pierrelonchampt)


    Hello,
    I would like to have a notification if a customer orders a particular product. Do you have any idea how I can do this?
    Thank you in advance !
    Pierre

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Ross V. a11n

    (@rossviviano)

    Automattic Happiness Engineer

    Hi Pierre,

    Just to clarify – are you looking to have the notification go to you as the site’s admin, the customer, or another email address? Would this notification be the default WooCommerce New Order email?

    Looking forward to hearing from you!

    Ross

    Thread Starter pierre

    (@pierrelonchampt)

    Thank you for your reply.
    I want to receive a notification as an administrator (or at another address, possibly) if in the order placed by a customer, there is a specific product (which I will identify by its ID for example).

    Plugin Support Aashik P – a11n

    (@aashik)

    Hello @pierrelonchampt

    I want to receive a notification as an administrator (or at another address, possibly) if in the order placed by a customer, there is a specific product (which I will identify by its ID for example).

    Advanced Notifications will let you set up custom notifications based on the following criteria:

    1. All purchases – Any order item will trigger a notification
    2. Product categories – Purchases of products in the product category will trigger a notification.
    3. Product shipping classes – Purchases of products in the product shipping class will trigger a notification.

    You can read more about it at Advanced Notifications – Documentation

    For any pre-sales questions on that, please open a support request in https://woocommerce.com/contact-us/#sales-form

    Plugin Support Aashik P – a11n

    (@aashik)

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

    Thread Starter pierre

    (@pierrelonchampt)

    Thanks everyone. I finally found the solution with the php code

    `add_filter( ‘woocommerce_email_recipient_new_order’, ‘conditional_recipient_new_email_notification’, 15, 2 );
    function conditional_recipient_new_email_notification( $recipient, $order ) {
    if( is_admin() ) return $recipient; // (Mandatory to avoid backend errors)

    ## — YOUR SETTINGS (below) — ##

    $targeted_ids = array(1, 2, 3); // products ids
    $addr_email = ‘[email protected]’; // email

    // Loop through orders items
    foreach ($order->get_items() as $item_id => $item ) {
    if ( in_array($item->get_variation_id(), $targeted_ids) || in_array($item->get_product_id(), $targeted_ids) ) {
    $recipient .= ‘, ‘ . $addr_email;
    break; // Found and added – We stop the loop
    }
    }

    return $recipient;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘new order notification only if there is a specific product’ is closed to new replies.