Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Display a Custom Delivery Message for WooCommerce Backordered Products?

Want to show the delivery timeframe for back-ordered products? With the given code snippet you can easily inform customers about the potential delay in delivery like this(“Please allow 20 days for delivery”). This notice message is shown on the individual product page and checkout page.

/* Backorder text as a notice message */

function backorder_notice_message($product_name) {
    return sprintf(__('Please allow 20 days for delivery of the backordered item "%s"', 'woocommerce'), $product_name);
}

function is_cart_page() {
    return function_exists('is_cart') && is_cart();
}
 
function ts_backorder_text($availability, $product) {
    if (is_cart_page() && $product->is_on_backorder()) {
        // Check if the notice has already been added
        if (!wc_notice_count('notice')) {
            wc_add_notice(backorder_notice_message($product->get_name()), 'notice');
        }
        return '';
    }
    return $availability;
} 
add_filter('woocommerce_get_availability', 'ts_backorder_text', 10, 2);
 
function ts_woocommerce_custom_cart_item_name( $_product_title, $cart_item, $cart_item_key ) {
    if (is_cart_page() && $cart_item['data']->is_on_backorder($cart_item['quantity'])) {
        // Check if the notice has already been added
        if (!wc_notice_count('notice')) {
            wc_add_notice(backorder_notice_message($_product_title), 'notice');
        }
        $_product_title .= ' - ' . __('Backordered', 'woocommerce');
    }
    return $_product_title;
}
add_filter('woocommerce_cart_item_name', 'ts_woocommerce_custom_cart_item_name', 10, 3);

Output

When a customer views a product page and the product is on backorder, the notice message will be displayed as shown in the below image.

How to Display a Custom Delivery Message for WooCommerce Backordered Products? - Tyche Softwares

Also, if customers proceed to the checkout process, they will be notified clearly about the delivery information of the back-ordered products.

How to Display a Custom Delivery Message for WooCommerce Backordered Products? - Tyche Softwares

Read Related Article: How to Hide Shipping Based on Product Tags in WooCommerce?

Such shipping notices are very useful in providing additional information to customers. In a similar way, you can also display custom message for products with limited stock in WooCommerce on the individual product page.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x