How to show percentage or saved amount for WooCommerce product sale price

Share this:

WooCommerce default display for sale price did not catch my eye as there are no mention about how many percentage or how much you saved which is the main attraction for most of the potential customers.

I will share 2 code snippet below so that you can use to optimize the display of the sale price at WooCommerce overview and product page.

 

1. Show percentage(%) saved for the product sale price

// Add save percent next to sale item prices.
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
  $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
  return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}


WooCommerce show percentage saved beside sale price

WooCommerce show percentage saved beside sale price

 

2. Show total amount saved for the product sale price

// Add save amount next to sale item prices.
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$saved = wc_price( $product->regular_price - $product->sale_price );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $saved );
}
WooCommerce show percentage saved beside sale price

WooCommerce show amount saved beside sale price

 

6 Comments

  1. It doesn’t work for me either :( .

    I put the above code in functions.php of my child theme, entered a sold out price for a product and nothing to see on the front end. I mean, sold out price is showed correctly but no info as shown on the screens above.

    I have a woocommerce dynamic pricing plugin but added to it a code that turns off the global discount rule on a given product when sold out price is given, so I hoped it will work then, but nothing.

  2. The code above works perfectly well but I need something more, I want to display total amount saved or percentage of amount saved on checkout page

Leave a Comment.