Issue summary:
A WooCommerce store needed a way to automatically hide or unhide products based on inventory levels. While WooCommerce provides native low-stock and out-of-stock notifications, it does not automatically change product visibility when stock drops below a certain threshold. The Freshy development team created a custom solution that uses per-product thresholds to toggle visibility dynamically, ensuring that products automatically disappear when inventory is low and reappear when restocked.
Issue background
The client wanted finer control over product visibility for both simple and variable products. Their main goal was to automatically remove items from the storefront once stock reached a defined low stock threshold.
WooCommerce’s default behavior supports global out-of-stock settings but does not allow unique thresholds per product. The client needed:
- A way to define product-specific thresholds.
- Automatic hiding of products that hit their threshold.
- Automatic reactivation when stock is replenished.
- Consistent handling across both simple and variation products.
While some threshold behavior had been implemented previously for product variations, the site still displayed simple products that were technically low in stock.
Diagnosis
The Freshy team analyzed how WooCommerce handles stock levels and discovered that:
- The low stock threshold setting only triggers an admin notification.
- The out-of-stock threshold globally sets products as unavailable but lacks per-item flexibility.
- There was no existing logic to change catalog visibility based on thresholds.
To achieve the client’s goals, the team proposed a custom script that uses product metadata to manage visibility and stock status dynamically.
Resolution steps
- Introduced a custom threshold field
Utilized WooCommerce’s_low_stock_amountfield for each product as a configurable threshold. Ensured that if the field was empty or invalid, the product would not be affected. - Implemented automated visibility toggling
When stock falls below or equals the threshold, the system automatically:- Sets the product’s
catalog_visibilitytohidden. - Changes the
stock_statustooutofstock. - Adds a meta flag
_auto_hidden_by_threshold = yesfor tracking.
When stock increases above the threshold, the system:
- Sets visibility back to
visible. - Restores
stock_statustoinstock. - Removes the
_auto_hidden_by_thresholdflag.
- Sets the product’s
- Added variation support
Extended logic to support variable products using the parent product’s threshold value. Variations that hit the threshold are marked as out of stock but not individually hidden. This avoids modifying WooCommerce’s core JavaScript for variations, keeping the solution stable and update safe. - Hooked into WooCommerce update actions
Used thewoocommerce_update_productaction to trigger the logic automatically when stock is updated. Ensured immediate updates when inventory changes occur via imports, edits, or API syncs. - Added optional scheduled checks (failsafe)
Created a fallback cron job that runs hourly to recheck all products. Ensures visibility is consistent even when third-party tools modify inventory directly in the database. - Extensive testing and quality assurance
Tested both simple and variable products for correct behavior. Verified that products without thresholds were unaffected. Confirmed performance remained stable on large catalogs.
Final outcome
The new automated threshold system ensures product visibility accurately reflects real inventory levels.
Results:
- Products automatically hide when they reach the low stock threshold.
- Hidden products reappear automatically when inventory is replenished.
- Works seamlessly for both simple and variable products.
- Reduces manual product management for the client’s inventory team.
- Maintains compatibility with imports and third-party syncing systems.
The system provides a more dynamic, error-proof inventory management experience while keeping the catalog accurate and user friendly.
Key takeaways
- WooCommerce’s default low stock notifications do not control visibility; custom logic is required.
- Automating visibility prevents customers from seeing unavailable products.
- Using per-product thresholds offers flexibility without complicating the catalog.
- Hooking into product update actions ensures real-time visibility changes.
- Adding an optional cron-based check guarantees reliability, even with external inventory imports.
If your WooCommerce store needs custom inventory management or automated visibility logic, contact the Freshy team to build a tailored solution that integrates seamlessly with your product catalog.