Stock qty on catalog pages — variations show 0 in stock
-
K so I got one for you php / hook experts here.
I’ve written a function to show sku numbers and stock quantities for my catalog pages. Works great, except that variable products show 0 in stock. Eh. So, I rewrote it:// ----------------------DISPLAY SKUs AND QTY ON CATALOG PAGES function shop_inventory(){ global $product; if($product->is_variation()) { echo '<div itemprop="productID" id="multi-sku">Part No. <br/><span>' . $product->sku . '</span></div>'; } else { echo '<div itemprop="productID" id="multi-sku">Part No. <br/><span>' . $product->sku . '</span></div> <div class="stock"><span>' . $product->stock . '</span> in stock<small>(backorders allowed)</small></div>'; } }; add_action( 'woocommerce_after_shop_loop_item_title', 'shop_inventory' );
But you can probably tell, that doesn’t work. I know the culprit is line 4:
if($product->is_variation()) {
..I just can’t seem to work out how to check to see if the product is a variable product type.. I’ve also tried:
if($product_type = variation) {
.. I’m at a loss. So close too!! Any ideas?
(Heres my original function, which doesn’t check for variable products:)add_action( 'woocommerce_after_shop_loop_item_title', 'shop_inventory' ); function shop_inventory(){ global $product; echo '<div itemprop="productID" id="multi-sku">Part No. <br/><span>' . $product->sku . '</span><div class="stock"><span>' . $product->stock . '</span> in stock<small>(backorders allowed)</small></div></div>'; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Stock qty on catalog pages — variations show 0 in stock’ is closed to new replies.