This example will show you how to detect if a certain product or a list of products were added to the cart, for example, to apply a special discount when purchasing several bundled products.

The formula
Take a look at the formula, we are using a function called CFO_CountProductInCart to check in current cart if the customer has added at least two products of a list of 4.
It uses product_id number, which can be seen easily in the URL of the product.
You can use CFO_CheckProductInCart too, which only returns true or false without returning quantity added.

We apply the special discount to ProductA if at least two products of B, C and D are added before.

Lines 3, 4 and 5 are using inline IF, take a look at the syntax if you are in doubt: Ternary Operator

To test the demo
– Go to Category Bundled Products and add to cart for example ProductB and ProductC.
– Enter in ProductA and add it to the cart, which is the product that has a special discount if other two were added.
– Look at the cart how ProductA has a detail that says “Purchase details: Bundle Discount 25%”
– Now, if you delete for example ProductB from the cart, the formula will detect it and remove the discount in ProductA, you will see “Purchase details: Regular price”

// Check if 2 of 3 bundled products are added to cart
// One quantity of each product is valid for us, so detect only if>0
$HasProductB = (CFO_CountProductInCart(65)>0 ? 1 : 0);
$HasProductC = (CFO_CountProductInCart(66)>0 ? 1 : 0);
$HasProductD = (CFO_CountProductInCart(67)>0 ? 1 : 0);

// We need 2 of 3
$BundleCount = $HasProductB + $HasProductC + $HasProductD;

// If two products in the cart, then apply discount
if($BundleCount>=2) {
	// Special Discount
	$eDiscount = 25;

	// Add some text to explain de discount
	CFO_SetOptionValue(24, "Bundle Discount 25%");
} else {
	// NO Special Discount
	$eDiscount = 0;

	// No aditional discount
	CFO_SetOptionValue(24, "Regular price");

// Apply special discount
$FinalPrice = $Price - ($Price * $eDiscount / 100);