Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active June 11, 2020 13:15
Show Gist options
  • Save bekarice/a8954958eb9b6af52713 to your computer and use it in GitHub Desktop.
Save bekarice/a8954958eb9b6af52713 to your computer and use it in GitHub Desktop.
Register multiple WooCommerce 2.2+ order statuses
/**
* Register new statuses - add an array for each status
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/
**/
function register_new_wc_order_statuses() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => 'Awaiting shipment',
'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>' )
) );
register_post_status( 'wc-packing', array(
'label' => 'Packing',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Packing <span class="count">(%s)</span>', 'Packing <span class="count">(%s)</span>' )
) );
// repeat register_post_status() for each new status
}
add_action( 'init', 'register_new_wc_order_statuses' );
// Add new statuses to list of WC Order statuses
function add_new_wc_statuses_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order statuses after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-awaiting-shipment'] = 'Awaiting shipment';
$new_order_statuses['wc-packing'] = 'Packing';
// Add a $new_order_statuses[key] = value; for each status you've added (in the order you want)
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_new_wc_statuses_to_order_statuses' );
@peterwebdesign
Copy link

when I change the order status to one of these statuses, the report system breaks and shows no sales

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment