Skip to content

Instantly share code, notes, and snippets.

@bernattorras
Last active November 22, 2021 01:54
Show Gist options
  • Save bernattorras/d978419540029ed6e2c03e56abd12570 to your computer and use it in GitHub Desktop.
Save bernattorras/d978419540029ed6e2c03e56abd12570 to your computer and use it in GitHub Desktop.
This snippet registers a new Order status.
<?php
/**
* Register new status
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/
**/
function register_holding_shipment_order_status() {
register_post_status( 'wc-holding-shipment', array(
'label' => 'Holding shipment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Holding shipment <span class="count">(%s)</span>', 'Holding shipment <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_holding_shipment_order_status' );
// Add to list of WC Order statuses
function add_holding_shipment_to_order_statuses( $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-holding-shipment'] = 'Holding shipment';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_holding_shipment_to_order_statuses' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment