[英]Total stock of all variations from a variable product In Woocommerce
I've tried to use Get the total stock of all variations from a variable product In Woocommerce , trying to make working this code:我尝试使用Get the total stock from a variable product In Woocommerce ,尝试使用以下代码:
add_action( 'woocommerce_after_shop_loop_item_title', 'display_variable_product_stock_quantity', 20 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
with this one:有了这个:
add_action( 'woocommerce_single_product_summary', 'display_variable_product_stock_quantity', 15 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
Or is it possible to get the total stock in the default element of quantities?或者是否可以在数量的默认元素中获得总库存? for example.例如。 The stocks will be displayed in the highlighted below:股票将显示在下面突出显示的位置:
Just use the following, changing of hook this way (for archive pages as shop) :只需使用以下内容,以这种方式更改钩子(对于作为商店的存档页面) :
add_action( 'woocommerce_after_shop_loop_item', 'display_variable_product_stock_quantity', 20 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 It should work as asked.它应该按要求工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.