Last active
July 29, 2021 05:59
-
-
Save Balakrishnan-flycart/c82ec2b47a30e2c2c6d6458eefbfeefc to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options
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
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from){ | |
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) { | |
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product); | |
if($calculate_discount_from == "regular_price"){ | |
$product_price = get_post_meta( $product_id, '_regular_price', true); | |
}else{ | |
$product_price = get_post_meta( $product_id, '_price', true); | |
} | |
} | |
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 ( class_exists('\Wdr\App\Helpers\Woocommerce')) { | |
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product); | |
if($calculate_discount_from == "regular_price"){ | |
$product_price = get_post_meta( $product_id, '_regular_price', true); | |
}else{ | |
$product_price = get_post_meta( $product_id, '_price', true); | |
} | |
} | |
return $product_price; | |
}, 10, 5); | |
add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function($price, $cart_item, $cart_object, $calculated_cart_item_discount){ | |
if(isset($cart_item) && isset($cart_item['yith_wapo_options']) && !empty($cart_item['yith_wapo_options'])){ | |
$add_on_price = 0; | |
foreach($cart_item['yith_wapo_options'] as $details){ | |
$add_on_price += isset($details['price']) ? $details['price'] : 0; | |
} | |
$price = $price + $add_on_price; | |
} | |
return $price; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment