Last active
December 7, 2021 08:40
-
-
Save AnanthFlycart/e58cb377976ab289626302d7591f461e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // PPOM Product Addon plugin compatibility (apply discount only on base price of product) | |
| if (!function_exists('advanced_woo_discount_rules_get_ppom_total_addon_price')) { | |
| function advanced_woo_discount_rules_get_ppom_total_addon_price($cart_item) { | |
| if (isset($cart_item['data']) && isset($cart_item['ppom']['fields']) && function_exists('ppom_get_field_prices') && function_exists('ppom_price_get_addon_total')) { | |
| $product_id = $cart_item['data']->get_id(); | |
| $variation_id = isset($cart_item['variation_id']) ? $cart_item['variation_id'] : ''; | |
| $ppom_fields_post = $cart_item['ppom']['fields']; | |
| $product_quantity = floatval($cart_item['quantity']); | |
| $ppom_field_prices = ppom_get_field_prices($ppom_fields_post, $product_id, $product_quantity, $variation_id, $cart_item); | |
| $total_addon_price = ppom_price_get_addon_total($ppom_field_prices); | |
| return $total_addon_price; | |
| } | |
| return 0; | |
| } | |
| add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from) { | |
| if (isset($cart_item['ppom']['fields'])) { | |
| $total_addon_price = advanced_woo_discount_rules_get_ppom_total_addon_price($cart_item); | |
| return $product_price - $total_addon_price; | |
| } | |
| return $product_price; | |
| }, 10, 5); | |
| add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from) { | |
| if (isset($cart_item['ppom']['fields'])) { | |
| $total_addon_price = advanced_woo_discount_rules_get_ppom_total_addon_price($cart_item); | |
| return $product_price - $total_addon_price; | |
| } | |
| return $product_price; | |
| }, 10, 5); | |
| add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function($price, $cart_item, $cart_object, $cart_item_key) { | |
| if (isset($cart_item['ppom']['fields'])) { | |
| $total_addon_price = advanced_woo_discount_rules_get_ppom_total_addon_price($cart_item); | |
| return $price + $total_addon_price; | |
| } | |
| return $price; | |
| }, 10, 4); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment