Show stock quantity
-
When a variation is mapped to a Product Bundle, the stock quantity is not displayed on the frontend product page, even when the bundle’s component products all have stock management enabled with quantities set.
Root cause
The
variation_get_manage_stockfilter (inproduct-bundles-variation-bundles.php) returns <code class=””>$variation_bundle->get_manage_stock(). Since a bundle product does not manage its own stock — its components do — this value is <code class=””>false. As a result, <code class=””>WC_Product_Variation::managing_stock() returns <code class=””>false, <code class=””>get_availability_text() produces an empty string, and theavailability_htmlreturned for the variation via <code class=””>get_available_variation() is blank. The stock quantity filter (woocommerce_product_variation_get_stock_quantity) correctly returns the inherited bundle stock quantity, but this value is never used because <code class=””>managing_stock() has already returned false.Steps to reproduce
- Create a Product Bundle with two component products, both with stock management enabled and quantities set.
- Create a variable product and map one variation to that bundle using the Variation Bundles field.
- Visit the product page and select the mapped variation from the dropdown.
- No stock quantity is displayed, despite the bundle’s <code class=””>get_bundle_stock_quantity() returning a valid figure.
Suggested fix
In the
variation_get_manage_stockfilter, rather than returning <code class=””>$variation_bundle->get_manage_stock(), check whether any of the bundle’s component products manage stock. If they do, return <code class=””>true. The admin variation form context check (did_actioncomparison) should be preserved to avoid affecting the backend UI.
You must be logged in to reply to this topic.