Introduction

  • Brief overview of WooCommerce’s built-in order statuses.
  • Why customizing order statuses is essential for advanced workflows (e.g., warehouses, dropshipping, service-based businesses).
  • Goal: Learn how to create custom order statuses and automate transitions using code and hooks.

Section 1: Understanding WooCommerce Order Statuses

  • Default statuses (pending, processing, on-hold, completed, cancelled, refunded, failed)
  • How statuses affect stock, emails, and visibility.
  • Where WooCommerce stores order status (post status under shop_order post type).

Section 2: Creating a Custom Order Status

Code Example:

add_action('init', 'register_custom_order_status');

function register_custom_order_status() {
    register_post_status('wc-awaiting-shipment', [
        'label'                     => 'Awaiting Shipment',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop('Awaiting Shipment <span class="count">(%s)</span>', 'Awaiting Shipment <span class="count">(%s)</span>')
    ]);
}

Section 3: Adding Custom Status to Order Dropdown

Code Example:

add_filter('wc_order_statuses', 'add_custom_order_status');

function add_custom_order_status($order_statuses) {
    $order_statuses['wc-awaiting-shipment'] = 'Awaiting Shipment';
    return $order_statuses;
}

Section 4: Automating Status Transitions

  • Using action hooks like woocommerce_order_status_changed
  • Example: Move to awaiting-shipment after payment is received.

Code Example:

add_action('woocommerce_order_status_processing', 'move_to_awaiting_shipment');

function move_to_awaiting_shipment($order_id) {
    $order = wc_get_order($order_id);
    $order->update_status('awaiting-shipment', 'Automatically moved after processing');
}

Section 5: Sending Custom Emails for New Status

  • Register a new email class.
  • Add custom email templates.
  • Hook into woocommerce_email_classes.

(Provide code scaffold or suggest using plugins like WP HTML Mail if not fully custom)

Section 6: Full Workflow Example

Scenario: Order flow for physical products

  1. processingawaiting-shipment (auto after payment)
  2. awaiting-shipmentshipped (manual)
  3. shippedcompleted (auto after 7 days)

(Provide logic using wp_schedule_single_event() or woocommerce_order_status_changed + custom status conditions)

Bonus: Visual Workflow Tools

Section 7: Clean Code Tips

  • Always prefix custom statuses (wc-yourstatus)
  • Use translatable strings for status labels
  • Store status transitions in metadata if needed for analytics

Conclusion

  • Summary of benefits of a custom order flow
  • Encourage modular, reusable code
  • Invite readers to automate and scale their WooCommerce operations