Skip to content

Instantly share code, notes, and snippets.

View outsourceappz's full-sized avatar

Outsource Appz outsourceappz

View GitHub Profile
@outsourceappz
outsourceappz / functions.php
Last active January 5, 2016 10:14 — forked from kloon/functions.php
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 );
if($percentage <= 0){
return $price;
}
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}