A custom WooCommerce order status: “Ready for pickup”
WooCommerce’s order statuses (pending, processing, on hold, completed, cancelled, refunded, failed) do not fit every shop. A store with local pickup needs a step between “processing” and “completed”: the order is packed and waiting at the counter. A custom status shows that in the order list, can be set in bulk, and can trigger an email to the customer.
Problem: A furniture store needs a “Ready for pickup” status that appears in the order list and the status dropdown, can be set for several orders at once, and tells the customer by email that the order can be collected.
Solution: Register the status with register_post_status() (with the wc- prefix), add it to the list with the wc_order_statuses filter, add a bulk action, and send the email on the woocommerce_order_status_ready-pickup action.
Registering the status
<?php
add_action( 'init', function () {
register_post_status( 'wc-ready-pickup', array(
'label' => _x( 'Ready for pickup', 'Order status', 'textdomain' ),
'public' => false,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: number of orders */
'label_count' => _n_noop( 'Ready for pickup <span class="count">(%s)</span>', 'Ready for pickup <span class="count">(%s)</span>', 'textdomain' ),
) );
} );
add_filter( 'wc_order_statuses', function ( $statuses ) {
$new = array();
foreach ( $statuses as $key => $label ) {
$new[ $key ] = $label;
if ( 'wc-processing' === $key ) {
$new['wc-ready-pickup'] = _x( 'Ready for pickup', 'Order status', 'textdomain' );
}
}
return $new;
} );
Orders are private data, so the status is not public. Inside WooCommerce the status is used without the prefix: $order->update_status( 'ready-pickup' ), $order->has_status( 'ready-pickup' ).
Bulk action and colour
<?php
add_filter( 'bulk_actions-edit-shop_order', function ( $actions ) {
$actions['mark_ready-pickup'] = __( 'Change status to ready for pickup', 'textdomain' );
return $actions;
} );
add_action( 'admin_head', function () {
echo '<style>.order-status.status-ready-pickup { background: #e8f5e9; color: #2e7d32; }</style>';
} );
WooCommerce handles bulk actions named mark_{status} itself, so no handler is needed. The CSS class of the status badge in the order list is status-{status}.
The email to the customer
The simplest way is a short email with WooCommerce’s own template wrapper, sent when the status changes:
<?php
add_action( 'woocommerce_order_status_ready-pickup', function ( $order_id, $order ) {
$mailer = WC()->mailer();
$heading = __( 'Your order is ready for pickup', 'textdomain' );
$message = sprintf(
__( 'Hello %1$s, your order #%2$s is ready. You can collect it at our store during opening hours.', 'textdomain' ),
esc_html( $order->get_billing_first_name() ),
esc_html( $order->get_order_number() )
);
$mailer->send(
$order->get_billing_email(),
$heading,
$mailer->wrap_message( $heading, '<p>' . $message . '</p>' )
);
}, 10, 2 );
For an email that the shop manager can switch on and off and edit in WooCommerce → Settings → Emails, extend WC_Email instead and register the class with the woocommerce_email_classes filter.
Reports and stock
Custom statuses are not “paid” for WooCommerce unless you say so. Add the status to the paid statuses, so it counts in reports and the order is not treated as unpaid:
<?php
add_filter( 'woocommerce_order_is_paid_statuses', function ( $statuses ) {
$statuses[] = 'ready-pickup';
return $statuses;
} );
NOTE: If the plugin that registers the status is deactivated, orders with that status disappear from the order list filters (the status is unknown), although they are still in the database. Before removing such a plugin, move the orders to a core status, for example “completed”.