How to add a custom or new order status in woocommerce wordpress
For add a custom or new order status in woocommerce store. just copy and paste below code into your theme's functions.php or in your custom plugins file.
For example i am add a shipping order status for order .
// register post status wc-shipping
add_action('init','register_shipping_post_status');
function register_shipping_post_status(){
register_post_status( 'wc-shipping', array(
'label' => 'Shipping',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipping <span class="count">(%s)</span>', 'Shipping <span class="count">(%s)</span>' )
) );
}
Now for add a shipping status into order status's dropdown use below code.
add_filter( 'wc_order_statuses','add_shipping_to_order_statuses' );
function add_shipping_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-shipping'] = 'Shipping';
}
}
return $new_order_statuses;
}
For example i am add a shipping order status for order .
// register post status wc-shipping
add_action('init','register_shipping_post_status');
function register_shipping_post_status(){
register_post_status( 'wc-shipping', array(
'label' => 'Shipping',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipping <span class="count">(%s)</span>', 'Shipping <span class="count">(%s)</span>' )
) );
}
Now for add a shipping status into order status's dropdown use below code.
add_filter( 'wc_order_statuses','add_shipping_to_order_statuses' );
function add_shipping_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-shipping'] = 'Shipping';
}
}
return $new_order_statuses;
}
Comments
Post a Comment