• Dani

    (@danicasati)


    Hi.
    I created a new order status with code snippet in my FUNCTIONS.PHP.

    Is it possible to create a new mail template that send automatically to vendor a message everytime that order status changes to custom one?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Leanza Francesco

    (@leanzafrancesco)

    Hi,
    and thank you for writing in!

    The goal you want to achieve it’s not so easy as it seems.
    At first, you should create a new WooCommerce email; to do it you should:

    • create a class for your email that extends the WooCommerce WC_Email class
    • use the WooCommerce woocommerce_email_classes actions to include your email class
    • create the email template file correctly, by using the woocommerce_email_header and woocommerce_email_footer actions into it

    After creating your WooCommerce email, you should send it when the order status changes, by using one of the order status transition actions you can find in WC_Order::status_transition method: for example, if your status is shipped, you could use the woocommerce_order_status_shipped action. Before sending the email, you could simply check if the order is assigned to a specific vendor or not.

    However, in this case, there are plugins that could easily allow you to achieve your goal.

    Thread Starter Dani

    (@danicasati)

    Could you post a sample code for detect order status changes to use in a new mail template?

    Plugin Support Alessio Torrisi

    (@alessio91)

    Hi there,
    WooCommerce provides the following hook to attach a function when an order changes own status.

    do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );

    You find this code woocommerce\includes\class-wc-order.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Send mail to vendor if order status changes’ is closed to new replies.