I have created a custom order status in my WooCommerce called Back Order (wc-backorder
):
/**
* Add custom status to order list
*/
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-backorder', array(
'label' => _x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
) );
}
/**
* Add custom status to order page drop down
*/
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-backorder'] = _x( 'Back Order', 'Order status', 'woocommerce' );
return $order_statuses;
}
Now I want to receive an email whenever an order is received that has been given the status quote. I've created a plugin based on this helpful article: How to Add a Custom WooCommerce Email
This link is containing my plugin source code and the functions.php code.
I added hook in function.php:
add_action( 'woocommerce_order_status_wc-order-confirmed', array( WC(), 'send_transactional_email' ), 10, 10 );
function so_27112461_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-order-confirmed';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'so_27112461_woocommerce_email_actions' );
Nothing happens when an order changed into the 'Back Order' status.
Any ideas?
I've tried loads of different hooks but I can't seem to get the trigger function to run.
I am on latest versions of WordPress and WooCommerce (3.0+)
Thanks
Try this
- EDIT / UPDATE -
As the code tutorial you are using is really outdated (2013) for this new mega major version 3.0+, this custom function hooked in
woocommerce_order_status_changed
action hook will do the job. So You will be able to send a customized Processing email notification, when order status is changed to your custom status.Here is that working and tested code for WC 3.0+:
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
AS your custom status is
wc-backorder
, but notwc-order-confirmed
, you just need to replace everywherewc-order-confirmed
bywc-backorder
.To make it work, you will have to change the 2 last hooked functions this way:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This should work (I can't test it as there is no the code of your custom plugin).
Reference source code:
woocommerce_order_status_{$this->status_transition[to]}
action hook