I need to display default variation price & with regular price & savings amount on my Woocommerce Homepage & Category Page
I found following code on this links answer Display lowest variation price and discounted percentage in WooCommerce
add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 );
function custom_price_format( $price, $product ) {
// Main Price
$regular_price = $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : $product->get_regular_price();
$sale_price = $product->is_type('variable') ? $product->get_variation_sale_price( 'min', true ) : $product->get_sale_price();
if ( $regular_price !== $sale_price && $product->is_on_sale()) {
// Percentage calculation and text
$percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
$percentage_txt = __(' Save', 'woocommerce' ).' '.$percentage;
$price = '<del>' . wc_price($regular_price) . '</del> <ins>' . wc_price($sale_price) . $percentage_txt . '</ins>';
}
return $price;
}
Now this code works perfectly on my site but this code shows price for 'Lowest' variation and savings in percentage where I need to show the price for 'Default' variation & Actual saving amount.