Lightning Rank - Private Blog Network

  • Home
  • Done 4 You PBN Service
  • Other Services
    • Amazon Associate Audit
    • Editorial Links
    • Buy Expired Domains
  • Contact
    • Affiliates

Display The Percentage Saved On WooCommerce Sale Products

November 17, 2015 By Jon Gillham Leave a Comment

At some point in time either yourself or a client will be building a WooCommerce site any may want to display the total percentage saved on WooCommerce sale products. By default WooCommerce does not display the percentage the customer will save on a sale product but thanks to Gerhard Potgieter this is easily possible by using an a elegant little WooCommerce filter.

Below is a screenshot of how a standard unmodified WooCommerce on sale product displays, You will notice it’s recommended price has a strike through and the sales price is the visible one.


woocommerce-product-without-sales-percentage

The screenshot below now shows the same product on the top left but this time after adding the filter to the site we now see the actual percentage saved on the recommended retail price appearing next to the prices.

woocommerce-product-with-sales-percentage

The percentage saved also displays on single sale product too like this example below.

woocommerce-single-product-with-sales-percentage

Add the PHP code below to your themes functions.php file to add the sales percentage total next to the 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 . '%' );
}

When adding to a theme you will still have to write a little CSS to suit the themes layout as this will only add the functionality to display the sales price but not style it to your theme in anyway.

Filed Under: WooCommerce, Wordpress Tutorials Tagged With: woocommerce, WooCommerce Sale Products, wordpress tutorial

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • What It takes to get to #1 in Google
  • Private Blog Network Building Service in 2016 – Is It Still Worth The Risk?
  • UpThemes Scale Back On Theme Options Within Their WordPress Themes
  • Create A WordPress Login Form Shortcode For Your Blog
  • WooThemes Back Online After Malicious Hack & Further DDoS Attack

Our Team

Jon Gillham

Father, Husband and mechanical engineer. Jon has the easy job he builds and tests systems that Kelley, Hmd and their teams execute!
Ahmed Ali

Ahmed is the man that makes sure everything runs smoothly. A true jack of all trades he makes sure each site is built to our high standards!

Copyright © 2022 . Experts at Harnessing the Power of Expired Domains to Help You Outrank Your Competition