For prices in variable products you need to use different methods specific to WC_Product_Variable
Class. A variable product is made of multiple product variations, so the prices of a variable product are its product variations prices.
You can get the min or the max prices of a variable product like:
global $product;
// Regular price min and max
$min_regular_price = $product->get_variation_regular_price( 'min' );
$max_regular_price = $product->get_variation_regular_price( 'max' );
// Sale price min and max
$min_sale_price = $product->get_variation_sale_price( 'min' );
$max_sale_price = $product->get_variation_sale_price( 'max' );
// The active price min and max
$min_price = $product->get_variation_price( 'min' );
$max_price = $product->get_variation_price( 'max' );
For a variable product, the method is_on_sale()
will return true if one of it's product variations is on saleā¦
You ca also use the method get_variation_prices()
that will give you a multidimensional array of all the product variations prices (active, regular and sale prices) set in the variable product.