Last active
March 14, 2023 11:10
-
-
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
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
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