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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.