Reputation: 347
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:
Upvotes: 1
Views: 652
Reputation: 254363
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.
Upvotes: 1