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

How to Add Custom “Out of Stock” Messages with Links in WooCommerce?

When a product goes out of stock in WooCommerce, the default message simply says “Out of stock”, which is just a static text. Many store owners want a more actionable and engaging message, allowing customers to easily request a notification when the product is back.

In this guide, we’ll show you how to replace the default out-of-stock text with a fully clickable message that redirects customers to a “Restock Request” page.

Solution: Add Custom “Out of Stock” Messages with Links in WooCommerce

The code modifies the default out-of-stock message to be clickable, directing customers to a restock page where they can submit their restocking request.

add_filter( 'woocommerce_get_availability', 'ts_custom_outofstock_message_full_link', 10, 2 );

function ts_custom_outofstock_message_full_link( $availability, $product ) {

    if ( ! $product->is_in_stock() ) {

        // URL of your restock request page
        $restock_page = site_url( '/restock-request/' );

        // Make the entire text clickable
        $replacement = sprintf(
            '<a href="%s" class="restock-link">%s</a>',
            esc_url( $restock_page ),
            esc_html__( 'This item is currently out of stock.', 'woocommerce' )
        );

        $availability['availability'] = $replacement;
    }

    return $availability;
}

Output

Normally, when a product goes out of stock, WooCommerce simply displays “Out of stock” on the product page.

With this snippet applied, the entire out-of-stock message becomes clickable.

Add “Out of Stock” Messages with Links

When a customer clicks on it, they are redirected to a specific page that you have defined (for example, a “Restock Request” page).

While making out-of-stock messages clickable is a great way to engage customers, you can also improve your product pages by hiding out of stock variations in woocommerce shop and product page. This ensures shoppers see only what they can buy, creating a smoother browsing experience.

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

Share It:

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.