Creating urgency is one of the most effective sales techniques in eCommerce.
A “Low Stock” badge helps customers make faster decisions by showing that a product is almost sold out.
In this tutorial, you will learn how to add a dynamic low stock alert in WooCommerce using hooks.
Why Low Stock Alerts Increase Conversions
When customers see limited availability, they are more likely to buy immediately instead of delaying the decision.
- Creates urgency and scarcity
- Reduces hesitation
- Increases conversion rates
- Encourages impulse buying
The WooCommerce Hook We Will Use
We will use:
woocommerce_before_shop_loop_item_title
This hook allows us to display custom badges on product listings in the shop loop.
Example Code
Add this code to your theme’s functions.php file or a custom plugin:
add_action('woocommerce_before_shop_loop_item_title', 'show_low_stock_badge');
function show_low_stock_badge() {
global $product;
if (!$product || !$product->is_in_stock()) {
return;
}
$stock = $product->get_stock_quantity();
if ($stock && $stock <= 5) {
echo '';
echo 'Low Stock: ' . $stock . ' left';
echo '';
}
}
How It Works
The function checks each product in the shop loop:
- If stock quantity is 5 or less → shows a red badge
- If stock is higher → nothing is displayed
- If product is out of stock → badge is not shown
Customization Ideas
- Change threshold per product category
- Add animations (pulse effect)
- Show “Almost Sold Out” instead of numbers
- Combine with countdown timers for promotions
<
