"Ready for Pickup" Order Status With Customer Email
Adds a "Ready for pickup" order status and emails the customer automatically when you set it, so click-and-collect customers know when to come in.
Opens WPIDE on
Code
$wpide_pickup_email = array(
'subject' => 'Your order #{order_number} is ready for pickup',
'heading' => 'Ready for pickup',
'body' => 'Hi {first_name}, good news: your order is packed and waiting for you at our shop. Please bring your order number when you collect it.',
);
add_filter( 'woocommerce_register_shop_order_post_statuses', function ( $statuses ) {
$statuses['wc-ready-pickup'] = array(
'label' => 'Ready for pickup',
'public' => false,
'exclude_from_search' => false,
'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>' ),
);
return $statuses;
} );
add_filter( 'wc_order_statuses', function ( $statuses ) {
$statuses['wc-ready-pickup'] = 'Ready for pickup';
return $statuses;
} );
$wpide_pickup_bulk = function ( $actions ) {
$actions['mark_ready-pickup'] = 'Change status to ready for pickup';
return $actions;
};
add_filter( 'bulk_actions-woocommerce_page_wc-orders', $wpide_pickup_bulk, 20 );
add_filter( 'bulk_actions-edit-shop_order', $wpide_pickup_bulk, 20 );
add_filter( 'woocommerce_order_is_paid_statuses', function ( $statuses ) {
$statuses[] = 'ready-pickup';
return $statuses;
} );
add_action( 'woocommerce_order_status_ready-pickup', function ( $order_id, $order = null ) use ( $wpide_pickup_email ) {
$order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
if ( ! $order || ! $order->get_billing_email() ) {
return;
}
$replace = array(
'{order_number}' => $order->get_order_number(),
'{first_name}' => $order->get_billing_first_name(),
);
$mailer = WC()->mailer();
$message = $mailer->wrap_message( $wpide_pickup_email['heading'], wpautop( esc_html( strtr( $wpide_pickup_email['body'], $replace ) ) ) );
$mailer->send( $order->get_billing_email(), strtr( $wpide_pickup_email['subject'], $replace ), $message );
$order->add_order_note( 'Ready for pickup email sent to the customer.' );
}, 10, 2 );
Notes
Edit the email wording in $wpide_pickup_email; it is sent with WooCommerce's email template and colours.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.