Skip to content

Instantly share code, notes, and snippets.

@themepaint
Last active March 5, 2019 19:59
Show Gist options
  • Save themepaint/b6b3ade013ee36b78dfb to your computer and use it in GitHub Desktop.
Save themepaint/b6b3ade013ee36b78dfb to your computer and use it in GitHub Desktop.
WooCommerce
<?php
/*Product DIscount Calculation*/
//put it on Function
function discount_product(){
global $product;
$discount = $product->sale_price ;
if ($discount) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
$wc_percent = $price .' <span class="product-discount">'. sprintf( __('%s', 'cruise' ), $percentage . '% OFF</span>' );
}
else{
$wc_percent = $price .' <span class="no_discount">'. sprintf( __('0%s', 'cruise' ), $percentage . '% OFF</span>' );
}
return $wc_percent;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment