Forked from webdados/percentage_woocommerce_sale_flash.php
Created
March 22, 2019 08:03
-
-
Save mvital/c4f9e8770e8037bf4e6124c14c595c52 to your computer and use it in GitHub Desktop.
Discount percentage on the WooCommerce "on sale" badge
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', 'percentage_woocommerce_sale_flash', 10, 3 ); | |
function percentage_woocommerce_sale_flash( $html, $post, $product ) { | |
if ( $html!='' ) { | |
$perc = round( 100 - ( $product->sale_price * 100 / $product->regular_price ) ); | |
if ( $perc>0 ) $html = '<span class="onsale">-'.$perc.'%</span>'; | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment