Home / Admin / Custom WooCommerce Status
Duplicate Snippet

Embed Snippet on Your Site

Custom WooCommerce Status

This is how to create a custom Woocommerce Status while being able to use the "Mark Shipped" functionality from WC Vendors using the "wcvendors_order_mark_shipped_statuses" filter.

Code Preview
php
<?php
**
 * Register new post status with WordPress
 */
add_action( 'init', 'wcvendors_custom_status_action' );
function wcvendors_custom_status_action() {
	register_post_status(
		'wc-custom-status',
		array(
			'label'                     => __( 'Custom Status', 'wc-vendors' ),
			'public'                    => true,
			'show_in_admin_status_list' => true,
			'label_count'               => _n_noop( 'Custom Status (%s)', 'Custom Status (%s)', 'wc-vendors' ),
		)
	);
}
/**
 * Add custom status to WC
 */
add_filter( 'wc_order_statuses', 'add_new_wc_status' );
function add_new_wc_status( $order_statuses ) {
	$order_statuses['wc-custom-status'] = _x( 'Custom Status', 'Order status', 'woocommerce' );
	return $order_statuses;
}
/**
 * Add status to WCV filter
 */
add_filter( 'wcvendors_order_mark_shipped_statuses', 'wcvendors_add_status_to_list' );
function wcvendors_add_status_to_list( $allow_mark_shipped_statuses ) {
	// Check if status does not exists then add the status without wc- prefix.
	if ( ! isset( $allow_mark_shipped_statuses['custom-status'] ) ) {
		$allow_mark_shipped_statuses[] = 'custom-status'; // Push new status to statuses array.
	}
	return $allow_mark_shipped_statuses;
}

Comments

Add a Comment