I'm trying to make a snippet for functions.php file that shows only one price of selected variation, thus omitting the price range displayed along with variation price on single product page. I'm using the following code:
add_action( 'woocommerce_before_single_product', 'my_remove_variation_price' );
$product_variations=$product_variable->get_available_variations;
function my_remove_variation_price() {
global $product;
if ( $product->is_type( 'variable' ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
}
}
The problem is when you have, for instance, two variations of single product and one goes out of stock, this script hides the price of one remaining variation on single product page. I was thinking maybe to have a COUNT of available variations per product and use IF to show them using standard single product template. Or maybe you have better idea how to solve that?
This is my Final working code, achieved with the help of LoicTheAztec answer:
To get the "in stock" variations count of a variable product on single product pages you can:
1) Use only php and Woocommerce WC_Product methods:
2) Use a SQL query with few php (quick and lighter):
Both codes are tested and work.