Displaying percentage of saving price

I would like to display the sale savings percentage next to the price.

I use this code in my function.php:

// 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 . '%' );

I have copied this code from a tutorial and it seems to work for everyone else. It also used to work for me but after a new update of WooCommerce, it is not working anymore.

I also deactivated all my CSS files to see if there is maybe a display:none and also I have deactivated all my other plugins. Still it does not work.

How can I figure out where the problem is?

Read more here: Displaying percentage of saving price

Leave a Reply

Your email address will not be published. Required fields are marked *