Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AnanthFlycart/b3e12bc788bfddf4994f66327288a092 to your computer and use it in GitHub Desktop.

Select an option

Save AnanthFlycart/b3e12bc788bfddf4994f66327288a092 to your computer and use it in GitHub Desktop.
<?php
$_product = wc_get_product( $atts['id'] );
$discount = false;
if (has_filter('advanced_woo_discount_rules_get_product_discount_price_from_custom_price')) {
$discount = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', 0, $_product, 1, 0, 'all', true, false);
if($discount !== false){
$percentage = ($discount['discounted_price'] / $discount['initial_price']) * 100;
}
}
if ($discount === false) {
$percentage = ($_product->get_price() / $_product->get_regular_price()) * 100;
}
echo 'for <span id="percent_val">' . abs(round($percentage, 0, PHP_ROUND_HALF_EVEN) - 100) . '%</span> off today';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment