Exclude discount for add on price compatible for YITH WooCommerce Product Add-ons & Extra Options
Exclude discounts for add-on prices compatible with YITH WooCommerce Product Add-ons & Extra Options.
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);