Skip to content

Instantly share code, notes, and snippets.

@hslaszlo
Forked from kloon/functions.php
Last active September 8, 2015 14:57
Show Gist options
  • Save hslaszlo/710e0a21a0fccf5b33a0 to your computer and use it in GitHub Desktop.
Save hslaszlo/710e0a21a0fccf5b33a0 to your computer and use it in GitHub Desktop.
WooCommerce add "Save x%" next to sale prices
<?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