Skip to content

Instantly share code, notes, and snippets.

@zorem
Last active October 9, 2020 13:02
Show Gist options
  • Save zorem/08ce930dddcff0c7ab0b890bb03310bd to your computer and use it in GitHub Desktop.
Save zorem/08ce930dddcff0c7ab0b890bb03310bd to your computer and use it in GitHub Desktop.
The function is going to add this new custom post status into the list of available order statuses within the WooCommerce “Orders” and “Edit Orders” pages so that we can actually use it. We want to pass in the current order statuses so that we can go through them and insert our order status into the list where we’d like it.
<?php
add_filter('wc_order_statuses', 'add_custom_status_to_order_statuses');
function add_custom_status_to_order_statuses($order_statuses)
{
// Replace 'my-custom-status' with your custom order status slug
// Replace 'My Custom Status' with your custom order status name
$new_order_statuses = array();
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ('wc-completed' === $key) {
$new_order_statuses['wc-my-custom-status'] = __('My Custom Status', 'text-domain'); x
}
}
return $new_order_statuses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment