简体   繁体   English

将woocommerce库存数量显示为单个数字

[英]Show woocommerce stock quantity as individual numbers

I want to load stock quantity of products on a custom page of my website. 我想在我的网站的自定义页面上加载产品的库存数量。 I use this to get the stock quantity 我用它来获得库存数量

        <p class="stock-m13"><?php echo $product->get_stock_quantity(); ?></p> 

This will return the exact number of stock quantity of a product, lets say 3. What I want to do is show the stock quantity as 1 1 1 instead of 3. I am thinking of a counter but I cannot really know the way to do it. 这将返回产品的确切库存数量,比方说3。我想做的是将库存数量显示为1 1 1而不是3。我在考虑一个柜台,但我真的不知道该怎么做它。

Thank you 谢谢

<?php
for ($s = 0; $s < $product->get_stock_quantity(); $s++) {
   echo "<p class='stock-m13'>".$product->get_stock_quantity()."</p>";
}
?>

or if you want display just 1 in quantity 或者如果您只想显示1个

<?php
for ($s = 0; $s < $product->get_stock_quantity(); $s++) {
   echo "<p class='stock-m13'>1</p>";
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM