Skip to content

Instantly share code, notes, and snippets.

@pietromalerba
Forked from kloon/functions.php
Last active August 29, 2015 14:08
Show Gist options
  • Save pietromalerba/1e7133a2635a0806e928 to your computer and use it in GitHub Desktop.
Save pietromalerba/1e7133a2635a0806e928 to your computer and use it in GitHub Desktop.
Woocommerce filter price
<?php
// Add save percent next to sale item prices.
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 . '%' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment