Skip to content

Instantly share code, notes, and snippets.

@ko31
Created January 22, 2019 02:58
Show Gist options
  • Save ko31/61ddf91dbc627f40aba423e6eec60ba7 to your computer and use it in GitHub Desktop.
Save ko31/61ddf91dbc627f40aba423e6eec60ba7 to your computer and use it in GitHub Desktop.
How to add custom status for Woocommerce.
<?php
// The following code adds the status "Reserved".
/**
* Register new status
*/
add_filter( 'init', function () {
register_post_status( 'wc-reserved', array(
'label' => 'Reserved',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Reserved <span class="count">(%s)</span>', 'Reserved <span class="count">(%s)</span>' )
) );
} );
/**
* Add to list of WC Order statuses
*/
add_filter( 'wc_order_statuses', function ( $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-reserved'] = 'Reserved';
}
}
return $new_order_statuses;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment