Display percentage % Discount @ Single product pages

I added this code in function.php of my theme to display the percentage after price and it works fine in woocommerce v2.6.14 but this snippet doesn’t work on the latest version.. How can I fix that?

// 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 . ‘%’ );
}

Read more here: Display percentage % Discount @ Single product pages

Leave a Reply

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