Skip to content
Advertisement

Display the stock availability for all product types in Woocommerce archive pages

I am using this code in showing the stocks of products:

JavaScript

And if the product is a variable I use this answer code to display the stock availability:
Get the total stock of all variations from a variable product In Woocommerce

How can I merge this codes in a single conditional function?

For example. if the products is a simple product, the other code for variable product will not display.

Advertisement

Answer

The following will handle the display of the stock availability for all product types in woocommerce archive product pages as shop.

To handle the stock availability display for other product types than variable, you can use the dedicated function wc_get_stock_html() instead, which will simplify the code.

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement