Display Regular & Sale Price for variable products on shop page – WooCommerce

I have a website with all the products having 2 variation attributes.

  1. Normal Item
  2. Exchange Item

Normal Item variation has a “Regular Price” & “Sale Price” compulsory. Exchange Item variation has only 1 regular price. I want to show all the 3 prices on the shop page where all the products are seen. I found the following code in woocommerce/templates/loops/price.php

Read More
<?php if ( $price_html = $product->get_price_html() ) : ?>
    <span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>

The same code is fetching different results for different themes, I dont understand what is causing this. For some themes it shows range of prices. For my theme this is displaying only the lowest price out of the 2 variations. How can I show something like this:

  1. Regular Price: 1000 (strikethrough)
  2. Sale Price : 800
  3. Exchange Price: 600

Number one and two being the regular & sale price of variation 1 of the product while number 3 is the regular price of variation 2.

Follwing is just and example of how I want it to be. striked is the regular price, ‘with old battery’ is the exchange price, and ‘without old battery’ is Regular price from normal item variation.
enter image description here


EDIT: So I checked function.php which has this code

add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
 add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
 function wc_wc20_variation_price_format( $price, $product ) {
 // Main Price
 $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
 $price = $prices[0] !== $prices[1] ? sprintf( __( 'Price: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 // Sale Price
 $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
 sort( $prices );
 $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'Previous Price: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 if ( $price !== $saleprice ) {
   $price = '<ins>' . $price . '</ins> <del>' . $saleprice . '</del>';
 }
   return $price;
 }

Gets me only exchange price values, I would like to get all.

Related posts