WooCommerce product table stock quantity column and low stock badge
The WooCommerce product table has a ready Stock quantity column, but it prints a bare number: 437, 2, or a dash. Shops usually want something friendlier: "More than 100 available" instead of an exact count, or an "Only 3 left" badge when a product or a workshop is about to sell out. Both are small changes to what the column prints, while the real stock in WooCommerce stays untouched. This page shows what the built-in stock columns display, how to replace the number with text, and how to add a low stock badge driven by the WooCommerce low stock threshold.
What the WooCommerce product table stock columns show
Three stock fields are available in the Field list of the Columns tab:
| Column | Cell | Sorting and filter |
|---|---|---|
| Stock quantity | The number of items in stock. A dash when the product does not track stock and when the quantity is 0; a negative number when backorders took the stock below zero | Sortable; a range slider in the Filter tab |
| Stock status | A green check for "In stock" and "On backorder", a red cross for "Out of stock" | A switch in the Filter tab that hides out of stock products |
| Manage stock | A check or a cross: whether the product tracks its stock quantity | Sortable |
Two related options sit elsewhere. The Title column has a Show labels option that adds small "featured", "on sale" and "out of stock" tags to the product name. And the In stock only switch in the Predefinition tab keeps only products with the "In stock" status (products on backorder are left out too), as described in the FAQ on showing only products in stock. There is no built-in low stock label with a threshold; the sections below add one.
Show the stock quantity column as text
Every column of the table is a field in the plugin's profile, and each field has an action callback that builds its cell from the product ID. The woot_profile_extend hook lets you replace that callback for stock_quantity, so the cell prints text while sorting and the range filter keep working on the real number stored in the _stock meta field:
/*
* Products tables: print the Stock quantity column as text.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('woot_profile_extend', function ($profile, $action) {
if ('woot_woocommerce_tables' !== $action || !isset($profile['stock_quantity'])) {
return $profile;
}
$profile['stock_quantity']['action'] = function ($post_id) {
$product = wc_get_product($post_id);
if (!$product) {
return '';
}
if (!$product->is_in_stock()) {
return 'Out of stock';
}
if ($product->is_on_backorder()) {
return 'Available on backorder';
}
if (!$product->managing_stock()) {
return 'In stock'; // the product does not count its items
}
$qty = (int) $product->get_stock_quantity();
if ($qty > 100) {
return 'More than 100 available';
}
return sprintf('%d available', $qty);
};
return $profile;
}, 10, 2);
Adjust the limits and the words to your shop; to show "100+" for any larger stock, change only the return values. If the table is translated in the Vocabulary tab, wrap each text in WOOT_Vocabulary::get() so it gets the translation of the current language. The same technique changes any other column, for example the icons of Stock status (its key is stock_status); the FAQ on modifying the cell output of a column by its key has another example.
Do not use the WooCommerce filter on get_stock_quantity() for this. It changes the quantity WooCommerce itself works with: the table hides its add to cart button when that number is 0 and uses it as the maximum of the cart quantity field, and stock checks in the cart read it too. A display change belongs in the column.
Add a low stock badge with the WooCommerce low stock threshold
Set the threshold in WooCommerce
WooCommerce already has the number you need. The store-wide value is under WooCommerce > Settings > Products > Inventory, Low stock threshold. Each product can override it in its Inventory tab, in its own Low stock threshold field, which appears once stock tracking is enabled for that product. A workshop with 12 seats can turn "almost full" at 3 while a bulk item turns at 50. Keep in mind that the store-wide value also triggers the low stock email notifications; if the badge needs a different number, write it into the snippet instead.
Register the badge column
/*
* Products tables: an "Availability" column with a low stock badge.
* Threshold: the product's Low stock threshold, otherwise the store-wide one.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('woot_profile_extend', function ($profile, $action) {
if ('woot_woocommerce_tables' !== $action) {
return $profile;
}
$profile['low_stock_badge'] = [
'title' => 'Availability',
'order' => false, // not sortable
'action' => function ($post_id) {
$product = wc_get_product($post_id);
// only products that count their stock and are in stock (not on backorder)
if (!$product || !$product->managing_stock() || !$product->is_in_stock() || $product->is_on_backorder()) {
return '';
}
$qty = (int) $product->get_stock_quantity();
$threshold = $product->get_low_stock_amount();
if ('' === $threshold || null === $threshold) {
$threshold = get_option('woocommerce_notify_low_stock_amount', 2);
}
if ($qty > 0 && $qty <= (int) $threshold) {
return sprintf('<span class="woot-low-stock-badge">Only %d left</span>', $qty);
}
return '';
},
];
return $profile;
}, 10, 2);
The field now appears in the Columns tab as Availability. Add it with Append column (or Prepend column), select Availability in Field, switch it Active and, if needed, Mobile. Drag the row to place the column next to the title or the price. Replace "Only %d left" with a fixed text such as "Almost full" if you prefer not to show the count. To put the badge into the Stock quantity column instead of a separate one, return the same <span> from the text snippet above for low quantities.
Style the badge
Paste the CSS into the table's Custom CSS tab and save it with the save button or CTRL+S. The plugin prefixes every rule there with the ID of this table, so other tables keep their look. For all tables at once, use the theme's Additional CSS instead.
.woot-low-stock-badge {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
background: #e8a33d;
color: #fff;
font-size: 12px;
line-height: 1.6;
}
/* optional: tint the whole row of a product that is running low */
tr:has(.woot-low-stock-badge) td {
background: #fff8ec;
}
Keep each closing brace on its own line, as above: the Custom CSS tab scopes rules by the line breaks after them. The row tint uses the CSS :has() selector, which current browsers support; older ones just skip it.
Variable products and backorders
- A variable product shows a quantity only when stock is managed on the product itself, in its Inventory tab. When each variation has its own stock, the product row shows a dash in Stock quantity and no badge, and the per-variation stock belongs in the variations table; see customizing the variations popup.
- Products on backorder count as available: Stock status shows a green check for them and the filter switch keeps them. The text snippet prints "Available on backorder" for them, and the badge skips them. An "On backorder" label in the Stock status column and the add to cart button at zero stock are covered in product table backorders.
- A product reaches "Out of stock" at the WooCommerce Out of stock threshold, which is not always 0. Both snippets read the stock status rather than comparing the number with 0, so they follow that setting.
If the badge or the text does not appear
- The product tracks stock: Manage stock shows a check for it in the table.
- Its quantity is above 0 and at or below the threshold that applies to it; check the product's own Low stock threshold first, since it overrides the store-wide value.
- The Availability column is Active in the table whose shortcode is on the page, and Mobile is on if you test on a phone.
- The snippet is active: a code snippets plugin may need the snippet switched on and set to run everywhere, because the table cells are built in an AJAX request, not in the page template.
- A page cache is cleared after the change.
If the column still shows the old output, ask on the WOOT support forum with the table shortcode and the snippet you use.