wordpresswoocommerceordersemail-notificationsvendors

WooCommerce Product Vendors: Send notification to vendor for new order received


I am using WooCommerce Product Vendors plugin for vendor management.

Currently, when a new order is received the notification is sent to customer and admin. Once admin change order status to Processing or Completed then the email is sent to Vendor.

But I need to send that notification email when an order is received.

Can this be achieved by creating a filter in functions.php or maybe by triggering product status change notification on order received?


Solution

  • Updated: Added "New booking" email notification Id…

    There is many ways to achieve that. Here I have 2 of them:

    1). The first one, based on email ID "new Order". It is tested and works:

    add_action ('woocommerce_email_customer_details', 'new_order_email_to_vendor', 20, 4 );
    function new_order_email_to_vendor( $order, $sent_to_admin, $plain_text, $email ){
        if( in_array( $email->id, ['new_order', 'new_booking'] ) ){ 
            $mailer['WC_Product_Vendors_Order_Email_To_Vendor']->trigger( $order );
        }
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.


    2). This is untested as it's based on order status change conditions. You can set in the if statement the "from" order statuses or some "to" order statuses or both…

    Here I use the "from" 'pending' order status only, as all orders are always set in pending status during the payment process in Woocommerce:

    add_action( 'woocommerce_order_status_changed', 'new_order_email_to_vendor', 10, 4 );
    function new_order_email_to_vendor( $order_id, $old_status, $new_status, $order ){
    
        if ( in_array( $new_status, array( 'processing','completed') ) { // <== Updated
            $emails = WC()->mailer()->get_emails();
            $emails['WC_Product_Vendors_Order_Email_To_Vendor']->trigger( $order );
        }
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.