Backorder Notice in the Cart and Checkout
Warns customers in the cart and at checkout which of their items are on backorder and roughly when they will ship, so nobody is surprised by a delay.
Opens WPIDE on
Code
$wpide_backorder_eta = '7 to 10 working days'; // Expected dispatch time for backorders.
$wpide_backorder_notice = function () use ( $wpide_backorder_eta ) {
$names = array();
foreach ( WC()->cart->get_cart() as $item ) {
$product = $item['data'];
if ( $product->managing_stock() && $product->is_on_backorder( (int) $item['quantity'] ) ) {
$names[] = $product->get_name();
}
}
if ( $names ) {
wc_print_notice( sprintf( '%1$s %2$s on backorder and will be dispatched in about %3$s.', esc_html( implode( ', ', $names ) ), 1 === count( $names ) ? 'is' : 'are', esc_html( $wpide_backorder_eta ) ), 'notice' );
}
};
add_action( 'woocommerce_before_cart', $wpide_backorder_notice );
add_action( 'woocommerce_before_checkout_form', $wpide_backorder_notice, 6 );
Notes
Set $wpide_backorder_eta to your usual restock time.
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.