1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php //get the sale price of the product whether it be simple, grouped or variable echo $sale_price = get_post_meta( get_the_ID(), '_price', true); //get the regular price of the product, but of a simple product $regular_price = get_post_meta( get_the_ID(), '_regular_price', true); //oh, the product is variable to $sale_price is empty? Lets get a variation price if ($regular_price == ""){
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id']; // Getting the variable id of just the 1st product. You can loop $available_variations to get info about each variation.
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->regular_price; } echo $regular_price;
|