Last active
March 23, 2017 21:44
-
-
Save yratof/4968eeffea7f51b46f94 to your computer and use it in GitHub Desktop.
Woocommerce: Show % saved
This file contains hidden or 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 save percent next to sale item prices, | |
* wrapped in a span + strong for CSS | |
* targeting with .saving{} and .saving strong{} | |
*/ | |
add_filter( 'woocommerce_sale_price_html', 'woocommerce_sales_price_saving', 10, 2 ); | |
function woocommerce_sales_price_saving( $price, $product ) { | |
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 ); | |
return $price . sprintf( __('<span class="saving">Save <strong>%s</strong></span>', 'woocommerce' ), $percentage . '%' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment