Last active
October 3, 2016 11:33
-
-
Save thesadoo/4c2cd63f4834ac6ba1ef599ac9f4c15d to your computer and use it in GitHub Desktop.
Get WooCommerce product's discount percentage with a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function off_percentage($id=null){ | |
$pid = ($id) ? $id : get_the_ID(); | |
$product = new WC_Product($pid); | |
$sale_price = $product->sale_price; | |
$regu_price = $product->regular_price; | |
$percentage = round( ( ( $regu_price - $sale_price ) / $regu_price ) * 100 ); | |
return $percentage; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment