Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/0c553582fcaac4a024bfa8406f09b4ff to your computer and use it in GitHub Desktop.
Save sarancartrabbit/0c553582fcaac4a024bfa8406f09b4ff to your computer and use it in GitHub Desktop.
Discount rules v2: To show the round off price
add_filter('advanced_woo_discount_rules_discount_prices_of_product', function ($discount_prices, $product, $quantity, $cart_item){
if (function_exists('wc_get_price_decimals')) {
$precision = 1;
if(isset($discount_prices['discounted_price'])){
$discount_prices['discounted_price'] = round($discount_prices['discounted_price'], $precision);
}
if(isset($discount_prices['discounted_price_with_tax'])){
$discount_prices['discounted_price_with_tax'] = round($discount_prices['discounted_price_with_tax'], $precision);
}
if(isset($discount_prices['discount_lines'])){
foreach ($discount_prices['discount_lines'] as $key => $value){
if($key !== 'non_applied'){
$line_discount = $discount_prices['discount_lines'][$key]['discounted_price'];
$discount_prices['discount_lines'][$key]['discounted_price'] = round($line_discount, $precision);
}
}
}
}
return $discount_prices;
}, 10, 4);
// Round Sale Badge Discount Percentage (zero decimal)
add_filter('advanced_woo_discount_rules_percentage_value_on_sale_badge', function ($percentage_value_rounded, $percentage_value, $_product) {
return round($percentage_value, 0);
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment