Skip to content

Instantly share code, notes, and snippets.

@luiseduardobraschi
Last active December 5, 2019 03:15
Show Gist options
  • Save luiseduardobraschi/8afafc4c565db68094da6bd97d7e9fa9 to your computer and use it in GitHub Desktop.
Save luiseduardobraschi/8afafc4c565db68094da6bd97d7e9fa9 to your computer and use it in GitHub Desktop.
[WooCommerce BR] Woocommerce - show discount percentage
<?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