Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/d3f62a2d83d8735ef5ffb85a2366d282 to your computer and use it in GitHub Desktop.
Save sarancartrabbit/d3f62a2d83d8735ef5ffb85a2366d282 to your computer and use it in GitHub Desktop.
Discount rules v2: Get max discount of product compare with discount rule discount and ACF max discount
add_filter('advanced_woo_discount_rules_discount_prices_of_product', function ($discount_prices, $product, $quantity, $cart_item){
if ($product && method_exists($product,'get_id') && function_exists('get_field')){
$product_id = $product->get_id();
$max_discount_price = get_field( "max_discount_amount", $product_id);
if (!empty($max_discount_price) && isset($discount_prices['discounted_price']) && class_exists('\Wdr\App\Controllers\ManageDiscount')) {
$calculator = \Wdr\App\Controllers\ManageDiscount::$calculator;
$discount_price = $discount_prices['initial_price'] - $discount_prices['discounted_price'];
if ($discount_price > $max_discount_price) {
$discount_prices['discounted_price'] = $discount_prices['initial_price'] - $max_discount_price;
$product_price_with_tax = $calculator->mayHaveTax($product, $discount_prices['discounted_price']);
$discount_prices['discounted_price_with_tax'] = $product_price_with_tax;
}
}
}
return $discount_prices;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment