Just wanted to share this with you as i was looking at the same exact problem.
Add this to your /theme/woocommerce/single-products/price.php
//get the regular price of the product, but of a simple product
$regular_price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale_price = get_post_meta( get_the_ID(), '_price', true);
if ($regular_price >= $sale_price){
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id'];
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->sale_price;
}
if ($sale_price >= $regular_price){
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id'];
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->regular_price;
}
Then find <meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" /> and replace it with <meta itemprop="price" content="<?php echo esc_attr( $regular_price ); ?>" />
That should now work for single, and variable products.
The above code works only for products that are variable, need to find a fix for ‘simple’ products. Anybody who could chip in?
This seems to work. Care to check?
// price fix for schema showing zero when variable
if($product->product_type=='variable') {
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id'];
$variable_product1= new WC_Product_Variation( $variation_id );
$regular_price = $variable_product1 ->regular_price;
$sales_price = $variable_product1 ->sale_price;
if ($sales_price == ""){
$display_price = $regular_price;
}
else {
$display_price = $sales_price;
}
}
else{
$display_price = $product->get_price();
}
Make sure to change this <meta itemprop="price" content="<?php echo esc_attr( $regular_price ); ?>" /> to <meta itemprop="price" content="<?php echo esc_attr( $display_price ); ?>" />
-
This reply was modified 9 years, 5 months ago by
jaysnl.