Skip to content

Instantly share code, notes, and snippets.

@kamalinfo
Created December 20, 2017 05:52
Show Gist options
  • Save kamalinfo/d8f5e2c1aa4093fa63b85174c5f6bb89 to your computer and use it in GitHub Desktop.
Save kamalinfo/d8f5e2c1aa4093fa63b85174c5f6bb89 to your computer and use it in GitHub Desktop.
<?php
global $product;
$discount = '';
$regurlar_price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale_price = get_post_meta( get_the_ID(), '_sale_price', true);
if($regurlar_price && $sale_price ){
$price = $sale_price * 100 / $regurlar_price;
$discount = round(100 - $price);
}
if($discount){
echo '<span class="brand-color2">-'.$discount.'%</span>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment