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

How to Display Custom Messages for Products with Limited Stock in WooCommerce?

Looking to display a custom message about limited stock in a product? This code snippet can help you.

function ts_custom_message_for_limited_stock_by_id( $title, $id ) {
// Set the threshold for limited stock
$stock_threshold = 5;
// Check if the product is in the specified IDs and has limited stock
$limited_stock_products = array( 35 ); // Add your product IDs here
if ( in_array( $id, $limited_stock_products ) ) {
$product = wc_get_product( $id );

// Check if the product stock is below the threshold
if ( $product->get_stock_quantity() !== '' && $product->get_stock_quantity() <= $stock_threshold ) {
$title .= '-<br> Hurry up!! Only 1 quantity left in stock';
}
}
return $title;
}
add_filter( 'the_title', 'ts_custom_message_for_limited_stock_by_id', 10, 2 );

Output

The below output shows that the custom message is displayed along with the product title on the WooCommerce single product page.

How to Display Custom Messages for Products with Limited Stock in WooCommerce? - Tyche Softwares

You can also display a custom delivery message for WooCommerce backordered products. This can help display delivery timeframes or any other relevant information specific to the customer’s location.

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

Share It:

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