Skip to content
Advertisement

Set a max displayed available stock quantity on Woocommerce archives for variable products

I want to set the maximum number of stock available items on Woocommerce shop pages.

I am using Display the stock availability for all product types in Woocommerce archive pages answer code, which does a great job, showing the available stock for variations in a Woocommerce shop.

But I want to show a maximum number, say 50, if the stock is actually in excess of 50. If there are 721 of an item in stock, I just want the number to show 50 to the customer.

I tried to add another if statement to the existing code but it simply added another line to the display, showing the actual total stock as well as my maximum number of 50, if the total was above 50.

Advertisement

Answer

The following that will limit the sock quantity display to 50 when it’s over 50, for variable products:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). It should work works.

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

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