Home / Admin / custom order status wpadmin
Duplicate Snippet

Embed Snippet on Your Site

custom order status wpadmin

Code Preview
php
<?php
/*
 * Register a custom order status
 *
 * @author Misha Rudrastyh
 * @url https://rudrastyh.com/woocommerce/order-statuses.html
 */
add_action( 'init', 'custom_order_status' );
function custom_order_status() {
	register_post_status(
		'wc-custom-packed',
		array(
			'label'		=> 'Packed',
			'public'	=> true,
			'show_in_admin_status_list' => true,
			'label_count'	=> _n_noop( 'Packed (%s)', 'Packed (%s)' )
		)
	);
	register_post_status(
		'wc-custom-shipping',
		array(
			'label'		=> 'Shipping',
			'public'	=> true,
			'show_in_admin_status_list' => true,
			'label_count'	=> _n_noop( 'Shipping (%s)', 'Shipping (%s)' )
		)
	);
}
// Add registered status to list of WC Order statuses
add_filter( 'wc_order_statuses', 'custom_add_status_to_list' );
function custom_add_status_to_list( $order_statuses ) {
	$new = array();
	foreach ( $order_statuses as $id => $label ) {
		
		if ( 'wc-completed' === $id ) { // before "Completed" status
			$new[ 'wc-custom-packed' ] = 'Packed';
			$new[ 'wc-custom-shipping' ] = 'Shipping';
		}
		
		$new[ $id ] = $label;
	}
	return $new;
	
}

Comments

Add a Comment