Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #4549281
Issue with applying discount to Smart Bundle with different VAT rates
Open

Comments

  • Alex started the conversation

    Dear WPC Product Bundles Support Team,
    I am using the Premium version of your plugin in WooCommerce and I have a Smart Bundle containing products with different VAT rates.
    My goal is:
    Apply a specific discount (e.g., 5.08%) to the entire bundle.
    Keep each product’s VAT accurate.
    Ensure products bought outside the bundle remain at normal price.
    Currently, I cannot see options for fixed price, editable regular price, or discount on total bundle. Applying a per-product discount gives incorrect totals in the cart.
    Could you please:
    Confirm if it is possible to apply a discount to the total bundle price while keeping individual VAT correct.
    Provide instructions on how to enable this, or suggest how to achieve it in the plugin.
    Thank you very much for your help.
    Sincerely,

    Alex Garcia.

  •  1,688
    Dustin replied

    Hi Alex,

    Please add the custom code below. (How to add custom code? ↗):

    add_action( 'woocommerce_before_calculate_totals', function ( $cart_object ) {
    	if ( ! defined( 'DOING_AJAX' ) && is_admin() ) {
    		// This is necessary for WC 3.0+
    		return;
    	}
    
    	foreach ( $cart_object->cart_contents as $cart_item_key => $cart_item ) {
    		if ( ! empty( $cart_item['woosb_parent_id'] ) ) {
    			WC()->cart->cart_contents[ $cart_item_key ]['woosb_price'] = $cart_item['data']->get_price();
    			$cart_item['data']->set_price( 0 );
    		}
    
    		if ( ! empty( $cart_item['woosb_ids'] ) && ! empty( $cart_item['woosb_price'] ) ) {
    			$cart_item['data']->set_price( $cart_item['woosb_price'] );
    		}
    	}
    }, 10000 );
    
    add_filter( 'woocommerce_cart_item_price', function ( $price, $cart_item ) {
    	if ( isset( $cart_item['woosb_parent_id'], $cart_item['woosb_price'] ) ) {
    		return wc_price( $cart_item['woosb_price'] );
    	}
    
    	return $price;
    }, 10000, 2 );
    
    add_filter( 'woocommerce_cart_item_subtotal', function ( $subtotal, $cart_item = null ) {
    	if ( isset( $cart_item['woosb_parent_id'], $cart_item['woosb_price'] ) ) {
    		return wc_price( $cart_item['woosb_price'] * $cart_item['quantity'] );
    	}
    
    	return $subtotal;
    }, 10000, 2 );

    The code will calculate the total of the sub-products and assign it to the main bundle product. This will ensure the coupon is applied to the bundle correctly.

    Let me know if it works as expected.

    Best regards,
    Dustin