Providing flat amount discounts is one of the most strategic ways to increase conversion rates, and we can use such an approach to make customers purchase products in bulk quantities.
The code helps to check the quantity of items for certain products present in the cart and when the threshold quantity is greater than or equal to the defined threshold value, a flat discount of $500 is applied.
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount_for_specific_products', 10, 1); function ts_add_custom_discount_for_specific_products($wc_cart) { if (is_admin() && !defined('DOING_AJAX')) return; $discount_amount = 500; $item_count = 0; $specific_product_ids = array(100, 457, 396); // Change this to the desired product IDs foreach ($wc_cart->get_cart() as $cart_item) { // Count each item in the cart $item_count += $cart_item['quantity']; // Check if the product ID is in the array of specific products if (in_array($cart_item['product_id'], $specific_product_ids)) { $specific_product_in_cart = true; } } // Check if there are at least 10 items in the cart and at least one specific product is present if ($item_count >= 10 && isset($specific_product_in_cart)) { // Apply the fixed discount $wc_cart->add_fee('Buy 10 Get $50 Discount', -$discount_amount, true); // Displaying a custom notice (optional) wc_clear_notices(); wc_add_notice(sprintf(__("Congratulations! You have qualified for a flat %s discount."), wc_price($discount_amount)), 'notice'); } }
Output
When the customer adds the products defined by the targeted product IDs in the code, and if the total quantity of these items is 10 or greater, the code applies a fixed discount of $500.
Similarly, you can also add dynamic bulk WooCommerce discount tiers based on quantity that will dynamically apply the discount based on the defined tiers.