1
votes

I'm new to Wordpress and I'm trying to figure out how to send an email when my order status is changed to a specific custom order status.

Here is my code:

function register_awaiting_shipment_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
    'label'                     => 'Shipped',
    'public'                    => true,
    'exclude_from_search'       => false,
    'show_in_admin_all_list'    => true,
    'show_in_admin_status_list' => true,
    'label_count'               => _n_noop( 'Awaiting shipment <span     class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)    </span>' )
) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );

// Add to list of WC Order statuses
function add_awaiting_shipment_to_order_statuses( $order_statuses) {

$new_order_statuses = array();

// add new order status after processing
foreach ( $order_statuses as $key => $status ) {

    $new_order_statuses[ $key ] = $status;

    if ( 'wc-processing' === $key ) {
        $new_order_statuses['wc-awaiting-shipment'] = 'Shipped';
       // WC()->mailer()->emails['wc-awaiting-shipment']->trigger($order_id);
    }
}

return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

How would I send an email to the customer when their order status is changed to this custom order status ('shipped')?

Thanks in advance

1

1 Answers

1
votes

You can use this plugin for your solution.

WooCommerce Order Status Change Notifier

Or

You can go to plugin settings => Email tab and install (enable) notifications that you want.

Hope this will help you