Last active
December 5, 2019 03:15
-
-
Save luiseduardobraschi/8afafc4c565db68094da6bd97d7e9fa9 to your computer and use it in GitHub Desktop.
[WooCommerce BR] Woocommerce - show discount percentage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_sale_flash', function( $string, $post, $product ) { | |
$regular_price = (float) $product->get_regular_price(); | |
$sale_price = (float) $product->get_price(); | |
$discount = round( 100 - ( $sale_price / $regular_price * 100 ), 1 ); | |
return sprintf( '<span class="onsale">%s%%</span>', $discount ); | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment