Skip to content

Instantly share code, notes, and snippets.

@joedooley
Forked from lmartins/price.php
Created November 30, 2015 18:06
Show Gist options
  • Save joedooley/d72a1af1ff972ee249d3 to your computer and use it in GitHub Desktop.
Save joedooley/d72a1af1ff972ee249d3 to your computer and use it in GitHub Desktop.
Show the sale savings percentage besides the product price and sale flash
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}
add_filter('woocommerce_sale_flash', 'my_custom_sale_flash');
function my_custom_sale_flash($text) {
global $product;
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return '<span class="onsale">-'.$percentage.'%</span>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment