Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howbizarre/b30c07f330383ca54a73756cfd10ceb9 to your computer and use it in GitHub Desktop.
Save howbizarre/b30c07f330383ca54a73756cfd10ceb9 to your computer and use it in GitHub Desktop.
Add or remove custom (or core) order statuses in WooCommerce

Add or remove custom (or core) order statuses in WooCommerce

Be careful - removing Core WooCommerce statuses is not a good idea at all, but you have this opportunity.

/**
* Remove Core Woocommerce oreder statuses with "wc_order_statuses" filter.
* Processing; Refunded; On Hold; Failed; Pending payment; Completed; Cancelled
* Removing Core statuses is not a good idea at all, but you have this opportunity.
*/
add_filter('wc_order_statuses', 'remove_order_statuses');
function remove_order_statuses($wc_statuses_arr)
{
// Refunded
if (isset($wc_statuses_arr['wc-refunded'])) {
unset($wc_statuses_arr['wc-refunded']);
}
// On Hold
if (isset($wc_statuses_arr['wc-on-hold'])) {
unset($wc_statuses_arr['wc-on-hold']);
}
return $wc_statuses_arr; // return result statuses
}
/**
* To register new status should call "init" action
* It will also be added to the status filters
*/
add_action('init', 'register_back_in_5_minutes_status');
function register_back_in_5_minutes_status()
{
register_post_status('wc-be-back', array(
'label' => 'I\'ll be back in 5 minutes',
'public' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('I\'ll be back in 5 minutes (%s)', 'Ill be back in 5 minutes (%s)')
));
}
/**
* Add registered status to list of WC Order statuses
*/
add_filter('wc_order_statuses', 'add_status');
function add_status($wc_statuses_arr)
{
$new_statuses_arr = array();
// add new order status after processing
foreach ($wc_statuses_arr as $id => $label) {
$new_statuses_arr[$id] = $label;
//if ('wc-completed' === $id) { // add new status after "Completed" status
$new_statuses_arr['wc-be-back'] = 'I\'ll be back in 5 minutes';
//}
}
return $new_statuses_arr;
}
/*
* Change statuses order in dropdown list
*/
add_filter('wc_order_statuses', 'change_statuses_order');
function change_statuses_order($wc_statuses_arr)
{
$new_statuses_arr = array(
'wc-be-back' => $wc_statuses_arr['wc-be-back'], // 0
'wc-processing' => $wc_statuses_arr['wc-processing'], // 1
'wc-completed' => $wc_statuses_arr['wc-completed'], // 2
'wc-cancelled' => $wc_statuses_arr['wc-cancelled'], // 3
// We remove "wc-refunded" in "wc_order_statuses" filter.
// Adding it without restoring will return an error.
//'wc-refunded' => $wc_statuses_arr['wc-refunded'], // 4
'wc-failed' => $wc_statuses_arr['wc-failed'], // 5
'wc-pending' => $wc_statuses_arr['wc-pending'], // 6
// We remove "wc-on-hold" in "wc_order_statuses" filter.
// Adding it without restoring will return an error.
//'wc-on-hold' => $wc_statuses_arr['wc-on-hold'] // 7
);
return $new_statuses_arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment