Last active
November 24, 2023 06:14
-
-
Save AnanthFlycart/8c8344a7096a70d7d33addcf7c9c52f4 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
| // Tested in PPOM for WooCommerce plugin version 32.0 | |
| if (!function_exists('advanced_woo_discount_rules_get_ppom_new_total_addon_price')) { | |
| function advanced_woo_discount_rules_get_ppom_new_total_addon_price($cart_item) { | |
| if (isset($cart_item['ppom']['fields']) && function_exists('ppom_get_field_prices') && function_exists('ppom_price_get_addon_total')) { | |
| $product_id = isset( $cart_item['product_id'] ) ? $cart_item['product_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 ); | |
| return ppom_price_get_addon_total( $ppom_field_prices ); | |
| } | |
| 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_new_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_new_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_new_total_addon_price($cart_item); | |
| return $price + $total_addon_price; | |
| } | |
| return $price; | |
| }, 10, 4); | |
| add_filter('advanced_woo_discount_rules_cart_strikeout_price_html', function($html, $old_html, $cart_item, $cart_item_key) { | |
| if (isset($cart_item['ppom']['fields']) && isset($cart_item['data']) && function_exists('wc_get_price_to_display')) { | |
| $total_addon_price = advanced_woo_discount_rules_get_ppom_new_total_addon_price($cart_item); | |
| if ($total_addon_price > 0) { | |
| $html .= ' + ' . wc_price(wc_get_price_to_display($cart_item['data'], ['price' => $total_addon_price, 'display_context' => 'cart'])); | |
| } | |
| } | |
| return $html; | |
| }, 10, 4); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment