Changing the names of ‘order status’ entries throughout WooCommerce.
I had a need to repurpose the ‘on-hold’ order status and this is what I did. This block changes the text in the admin and customer panels in three places within WordPress.
//Code came from: https://quadlayers.com/edit-custom-order-status-in-woocommerce/
//////// renames the main order status in admin and customer interface. (In this case from 'on hold' to 'Ready for Pickup') Available hooks: wc-completed, wc-processing, wc-pending, wc-on-hold.
function my_rename_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
if ( 'wc-on-hold' === $key ) {
$order_statuses['wc-on-hold'] = _x( 'Ready for Pickup', 'Order status', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'my_rename_status' );
///////// renames main admin panel filter buttons
foreach( array( 'post', 'shop_order' ) as $hook )
add_filter( "views_edit-shop_order", 'ts_order_status_top_changed' );
function ts_order_status_top_changed( $views ){
if( isset( $views['wc-on-hold'] ) )
$views['wc-on-hold'] = str_replace( 'On hold', __( 'Pickup', 'woocommerce'), $views['wc-on-hold'] );
return $views;
}
///////// renames main admin panel bulk edit dropdown
add_filter( 'bulk_actions-edit-shop_order', 'ts_bulk_actions_order_status', 20, 1 );
function ts_bulk_actions_order_status( $actions ) {
$actions['mark_on-hold'] = __( 'Change status to pickup', 'woocommerce' );
return $actions;
}
And this block changes the text in the email area using a translate function. Not needed, but it looks nicer in the backend…
add_filter( 'woocommerce_shipping_package_name', 'custom_shipping_package_name' );
function custom_shipping_package_name( $name ) {
return 'Pickup';
}
function fix_woocommerce_strings( $translated, $text) {
// STRING 1
$translated = str_ireplace( 'on-hold', 'Pickup', $translated );
return $translated;
}
add_filter( 'gettext', 'fix_woocommerce_strings', 999, 3 );
Change Order Status depending on payment type
I wanted to have the ‘Check’ orders placed automatically into ‘Processing’.
//Redundantly change 'pay by check' order status to 'payment pending' otherwise the next step doesn't seem to work right.
add_filter( 'woocommerce_cheque_process_payment_order_status', 'myplugin_change_order_status', 10, 1 );
function myplugin_change_order_status($status){
return 'agent-processing';
}
//Now change status again of 'pay by check' now to 'processing' Note: If you don't set this to 'agent-processing' first, it sends out the 'on-hold' email, even though woo shows the status as 'processing'.
add_filter( 'woocommerce_cheque_process_payment_order_status', 'myplugin_change_order_status2', 10, 1 );
function myplugin_change_order_status2($status){
return 'processing';
}
Send email when going from processing to on-hold
Sends on-hold email, when status changes from ‘processing’ instead of from just ‘awaiting payment’ or ‘canceled’. I’m not sure where I got the code…
add_filter( 'woocommerce_email_actions', 'add_another_email_action' );
function add_another_email_action( $array ) {
$array[]='woocommerce_order_status_processing_to_on-hold';
return $array;
}
add_action( 'woocommerce_email', 'hook_another_email_on_hold' );
function hook_another_email_on_hold( $email_class ) {
add_action( 'woocommerce_order_status_processing_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger' ) );
}
Add new ‘Order Status’ entry in woo
This registers a new order status post entry for a new order status type. This came from: https://quadlayers.com/edit-custom-order-status-in-woocommerce/
// Register new order status by creating a new post in this case "Waiting"
function register_wait_call_order_status() {
register_post_status( 'wc-waiting', array(
'label' => 'Waiting',
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Waiting (%s)', 'Waiting (%s)' )
) );
}