add_filter('advanced_woo_discount_rules_do_apply_price_discount', function ($apply, $price, $cart_item, $cart_object){
if(!empty($cart_item['bundled_items'])){
$apply = false;
}
return $apply;
}, 10, 4);
add_filter('woocommerce_product_get_price', function ($price, $product){
if(isset($product->awdr_discount_price)){
if($product->awdr_discount_price){
$price = $product->awdr_discount_price - $product->awdr_product_original_price;
}
}
return $price;
}, PHP_INT_MAX, 2);
add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function ($price, $cart_item){
if(!empty($cart_item["data"])){
$cart_item["data"]->awdr_discount_price = $price;
$cart_item["data"]->awdr_product_original_price = advanced_woo_discount_rules_get_bundle_item_price_for_calculate_discount($cart_item, 0);
}
return $price;
}, 10, 2);
add_action('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function ($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if(!empty($cart_item['bundled_items'])){
$price = advanced_woo_discount_rules_get_bundle_item_price_for_calculate_discount($cart_item, $product_price);
$product_price = $price;
}
return $product_price;
}, 10, 5);
add_action('advanced_woo_discount_rules_product_price_on_before_calculate_discount', function ($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if(!empty($cart_item['bundled_items'])){
$price = advanced_woo_discount_rules_get_bundle_item_price_for_calculate_discount($cart_item, $product_price);
$product_price = $price;
}
return $product_price;
}, 10, 5);
if(!function_exists('advanced_woo_discount_rules_get_bundle_item_price_for_calculate_discount')){
function advanced_woo_discount_rules_get_bundle_item_price_for_calculate_discount($cart_item_data, $bundle_product_price){
$bundled_value = $bundle_product_price*$cart_item_data[ 'quantity' ];
$bundle_totals = array(
'line_subtotal' => $cart_item_data[ 'line_subtotal' ],
'line_total' => $cart_item_data[ 'line_total' ],
'line_subtotal_tax' => $cart_item_data[ 'line_subtotal_tax' ],
'line_tax' => $cart_item_data[ 'line_tax' ],
'line_tax_data' => $cart_item_data[ 'line_tax_data' ]
);
if(function_exists('wc_pb_get_bundled_cart_items')){
foreach ( wc_pb_get_bundled_cart_items( $cart_item_data, WC()->cart->cart_contents, true ) as $child_item_key ) {
$child_cart_item_data = WC()->cart->cart_contents[ $child_item_key ];
$bundled_product = $child_cart_item_data[ 'data' ];
$bundled_product_qty = $child_cart_item_data[ 'quantity' ];
$bundled_product_value = isset( $bundled_product->bundled_value ) ? $bundled_product->bundled_value : 0.0;
if(method_exists($bundled_product, 'get_price')){
$bundled_product_value = $bundled_product->get_price();
}
// Aggregate price of physically packaged child item - already converted to virtual.
if ( $bundled_product_value ) {
$bundled_value += $bundled_product_value * $bundled_product_qty;
$bundle_totals[ 'line_subtotal' ] += $child_cart_item_data[ 'line_subtotal' ];
$bundle_totals[ 'line_total' ] += $child_cart_item_data[ 'line_total' ];
$bundle_totals[ 'line_subtotal_tax' ] += $child_cart_item_data[ 'line_subtotal_tax' ];
$bundle_totals[ 'line_tax' ] += $child_cart_item_data[ 'line_tax' ];
$child_item_line_tax_data = $child_cart_item_data[ 'line_tax_data' ];
$bundle_totals[ 'line_tax_data' ][ 'total' ] = array_merge( $bundle_totals[ 'line_tax_data' ][ 'total' ], $child_item_line_tax_data[ 'total' ] );
$bundle_totals[ 'line_tax_data' ][ 'subtotal' ] = array_merge( $bundle_totals[ 'line_tax_data' ][ 'subtotal' ], $child_item_line_tax_data[ 'subtotal' ] );
}
}
}
return $bundled_value/$cart_item_data['quantity'];
}
}