Product Archive, Product Page

WooCommerce Show Percentage Saving Amount On Sale Product

WooCommerce sale product showing percentage saving

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

  • This snippet allows you to display the percentage saving amount on sale products on the single product template and on the loop items
/**
 * Snippet Name:	WooCommerce Display Percentage Saving Amount On Sale Products
 * Snippet Author:	ecommercehints.com
 */

// Simple Products
add_filter( 'woocommerce_get_price_html', 'ecommercehints_display_percentage_savings_amount_on_sale_simple_products', 10, 2 );
function ecommercehints_display_percentage_savings_amount_on_sale_simple_products( $price, $product ) {
    if ( $product->is_on_sale() && $product->is_type( 'simple' ) ) {
        $regular_price = $product->get_regular_price();
        $sale_price = $product->get_sale_price();
		$savings_calculation = $sale_price * 100 / $regular_price;
		$savings_total = 100 - $savings_calculation;
        $price .= '<br><small>You save ' . round($savings_total) . '%</small>';
	}
    return $price;
}

// Variable Products (shows when variations have been selected)
add_filter( 'woocommerce_available_variation', 'ecommercehints_display_percentage_savings_amount_on_sale_variable_products', 10, 3 );
function ecommercehints_display_percentage_savings_amount_on_sale_variable_products( $data, $product, $variation ) {
    if( $variation->is_on_sale() ) {
        $savings_amount = $data['display_regular_price'] - $data['display_price'];
        $percentage_amount = round( $saved_amount / $data['display_regular_price'] * 100 );
        $data['price_html'] .= 'You save ' . $percentage_amount.  '%';
    }
    return $data;
}

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER