WooCommerce Order Status Overview
December 24, 2024 ยท AI Conversations
### Built-in Order Statuses
1. **Pending Payment** (`pending`):
– Order created but awaiting payment.
– Stock is not reduced.
– The customer needs to pay.
2. **Processing** (`processing`):
– Payment received, and stock is reduced.
– The order is waiting for fulfillment (e.g., shipping).
– This status is common for physical products.
3. **On Hold** (`on-hold`):
– Awaiting confirmation (e.g., manual payment verification).
– Stock is reduced but no further action is taken until confirmed.
4. **Completed** (`completed`):
– Order fulfilled (e.g., shipped) and marked as complete.
– No further actions are needed.
5. **Cancelled** (`cancelled`):
– Order cancelled by the admin or customer.
– No payment was received.
– Stock is restored if it was reduced.
6. **Refunded** (`refunded`):
– Payment refunded to the customer.
– Admin manually sets this status.
7. **Failed** (`failed`):
– Payment failed or was declined (unpaid order).
– Stock is not reduced.
### Customizing Order Status
You can add custom order statuses if needed for your workflow. Use the `register_post_status()` function to define new statuses and then include them in WooCommerce using filters like `wc_order_statuses`.
### Programmatically Changing Order Status
To change an order's status programmatically:
$order_id = 123; // Replace with your order ID
$order = wc_get_order($order_id);
if ($order) {
$order->update_status('completed', 'Order completed successfully.');
}
### Hooks for Order Status Changes
WooCommerce provides hooks for responding to status changes:
1. **Before Status Change**
add_action('woocommerce_order_status_changed', function($order_id, $old_status, $new_status, $order) {
// Your custom logic here
}, 10, 4);
2. **Specific Status Changes**
add_action('woocommerce_order_status_completed', function($order_id) {
// Logic for completed orders
});
Let me know if you need help customizing or debugging WooCommerce order statuses!