简体   繁体   中英

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:

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). It should work as asked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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