Wordpress WooCommerce Knowledge

Creating Custom Order Statuses for WooCommerce Orders

Write to us if you have any questions about our plugins or specific requirements and bug fixes.

Todays Topic: Creating Custom Order Statuses for WooCommerce Orders

WORDPRESS / WOOCOMMERCE KNOWLEDGE

Weblabs-UI

More efficiency for Wordpress and WooCommerce! Better overview and smart tools to take your website to the next level.
Learn More

Customizing your WooCommerce shop can enhance the efficiency of your order management process. One powerful way to do this is by creating custom order statuses. Whether you need to add an intermediate step in your order workflow or distinguish special orders from regular ones, custom statuses can tailor the backend to your business needs. Tools like Weblabs-UI, WP Code, or Code Snippets are highly recommended for safely incorporating the required code into your WooCommerce installation.


Approach 1 – PHP Solution

The PHP solution involves using hooks and filters provided by WooCommerce to register and manage new order statuses. This method offers extensive control and flexibility, allowing you to integrate these statuses seamlessly with your order processing logic.

Example Code:

PHP
<?php
// Register a new custom order status called "Custom Pending"
function register_custom_order_status() {
    register_post_status( 'wc-custom-pending', array(
        'label'                     => 'Custom Pending',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Custom Pending <span class="count">(%s)</span>', 'Custom Pending <span class="count">(%s)</span>' )
    ) );
}
add_action( 'init', 'register_custom_order_status' );

// Add the new order status to the list of WooCommerce order statuses
function add_custom_order_status( $order_statuses ) {
    $new_order_statuses = array();

    // Insert new status after "pending"
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-pending' === $key ) {
            $new_order_statuses['wc-custom-pending'] = 'Custom Pending';
        }
    }
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_custom_order_status' );
?>

How It Works:

The provided code registers a new order status “Custom Pending” using the register_post_status() function and then adds it to the list of order statuses displayed in the WooCommerce dashboard via the wc_order_statuses filter. This ensures that when you process orders, the new status is available for selection and management.


Approach 2 – Visual Enhancement with CSS

While PHP handles the backend logic, you might also want to improve the visual representation in the admin area. Custom CSS can be applied to highlight orders with the new status.

Example CSS Code:

Code
/* Customize the appearance of the custom order status row in the WooCommerce orders table */
.status-wc-custom-pending {
    background-color: #fff3cd;
    color: #856404;
    font-weight: bold;
}

Integration:

You can add this CSS code to your admin area by injecting it via the admin_head hook:

PHP
<?php
function custom_admin_order_status_styles() {
    echo '
    <style>
        .status-wc-custom-pending {
            background-color: #fff3cd;
            color: #856404;
            font-weight: bold;
        }
    </style>
    ';
}
add_action('admin_head', 'custom_admin_order_status_styles');
?>

This way, your custom order status will visually stand out in the order list, making it easier for you and your team to manage orders that require special attention.


Approach 3 – Using a Specialized Plugin

For a more streamlined experience, consider using a specialized plugin like Weblabs-UI. These plugins often come with user-friendly interfaces that let you add, edit, and manage custom order statuses without the need for custom code. With plugin-based solutions, benefits include:

  • An intuitive interface to manage order statuses
  • Extended settings to control notifications and workflows associated with the new statuses
  • Seamless integration with other WooCommerce features and third-party tools

Plugins like Weblabs-UI are especially advantageous for agencies or larger stores that prefer to avoid direct coding, ensuring a more cohesive and professional admin experience.


Conclusion

Creating custom order statuses in WooCommerce can significantly improve the management and organization of your orders. With a PHP solution, you gain the flexibility to define and integrate new statuses within your order workflows. Complementing the backend changes with custom CSS further enhances the user experience by visually differentiating these orders. For those who prefer a less code-intensive approach, specialized plugins like Weblabs-UI offer comprehensive and user-friendly solutions.

Experiment with these approaches to determine the best fit for your store’s needs, and enjoy a more tailored and efficient order management system that perfectly aligns with your business operations.

More efficiency for Wordpress and WooCommerce! Better overview and smart tools to take your website to the next level.