Reputation: 1239
I tried this snippet: https://gist.github.com/vividvilla/7137659#file-sale-flash-php to show % discount on sales badge in WooCommerce.
The problem is that for variations that do not have any discount, a badge of 0% is displayed. Can anyone guide me on how to avoid that.
Optionally, for variations I would like to show "Upto x%" instead of % dicount.
Upvotes: 0
Views: 6555
Reputation: 350
At line 42, replace
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
echo $price . sprintf( __('%s', 'woocommerce' ), $percentage . '%' ); ?></div>
with
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
if ( $percentage )
echo $price . sprintf( __('%s', 'woocommerce' ), $percentage . '%' )
else
echo $price;
?>
Looks like $maximumper
is already showing the maximum discount percentage.
Are you just trying to change the words?
At line 32,change
echo $price . sprintf( __('Up to %s', 'woocommerce' ), $maximumper . '%' ); ?></div>
Upvotes: 1