Do you know how to insert this code into WordPress?
Follow this Screenshot Tutorial
1. Go to plugin: Search Wp Code > Install > Activate

2. Click > Add New

3. Click > Add Your Custom Code

3. Click > Add Your Custom Code

4. Enter Code > Copy and paste the code > active > update > finish ..
/**
* Apply ₹999 for First 3 Items + Normal Pricing for Extras
*/
function apply_3_plus_pricing() {
// Exit in admin panel
if (is_admin() && !wp_doing_ajax()) return;
$cart = WC()->cart;
if (!$cart || $cart->is_empty()) return;
$target_quantity = 3;
$fixed_price = 999; // Changed to ₹999
$total_items = $cart->get_cart_contents_count();
// Apply pricing logic only if cart has 3+ items
if ($total_items >= $target_quantity) {
$remaining_to_count = $target_quantity;
$first_3_total = 0;
// Calculate value of first 3 items
foreach ($cart->get_cart() as $cart_item) {
$item_qty = $cart_item['quantity'];
$item_line_total = $cart_item['line_total'];
$take_qty = min($item_qty, $remaining_to_count);
$proportion = $take_qty / $item_qty;
$first_3_total += $item_line_total * $proportion;
$remaining_to_count -= $take_qty;
if ($remaining_to_count <= 0) break;
}
// Calculate price adjustment
$adjustment = $fixed_price - $first_3_total;
// Apply adjustment
if ($adjustment != 0) {
$label = ($adjustment > 0)
? 'Additional Charges (First 3 Items)'
: 'Discount (First 3 Items)';
$cart->add_fee($label, $adjustment, false);
}
// Updated success message
wc_add_notice(
sprintf('Special offer applied! First 3 items for ₹%d', $fixed_price),
'success'
);
} else {
// Updated reminder message
if ($total_items > 0) {
$needed = $target_quantity - $total_items;
wc_add_notice(sprintf(
'Add %d more item(s) to unlock first 3 items for ₹999!',
$needed
), 'notice');
}
}
}
// Hooks remain the same
add_action('woocommerce_cart_calculate_fees', 'apply_3_plus_pricing');
add_action('woocommerce_before_cart', 'apply_3_plus_pricing');
add_action('woocommerce_before_checkout_form', 'apply_3_plus_pricing');

How It Works with ₹999 Pricing:
- First 3 Items at Fixed ₹999
The first 3 items in the cart (by quantity) are bundled together for ₹999 total. - Additional Items at Regular Price
Any items beyond the first 3 retain their original individual pricing. - Automatic Price Adjustment
- If the first 3 items’ total is ₹800: ₹199 surcharge added
- If the first 3 items’ total is ₹1200: ₹201 discount applied
- If exactly ₹999: No adjustment needed
- Clear Pricing Breakdown
- The adjustment appears as either:
“Additional Charges (First 3 Items)” or
“Discount (First 3 Items)” - Customers see exactly why their total changed
- The adjustment appears as either:
Example Scenarios:
Cart Contents | First 3 Items Value | Adjustment | Final Total |
---|---|---|---|
3 × ₹300 | ₹900 | +₹99 | ₹999 |
4 items | First 3 = ₹700 | +₹299 | ₹999 + ₹(4th item price) |
5 items | First 3 = ₹1500 | -₹501 | ₹999 + ₹(4th+5th items) |
2 items | N/A | None | Regular pricing |
Key Benefits
Tax Compliant
Price adjustments are shown as non-taxable fees.
Encourages Larger Orders
Customers often add extra items to maximize value from the ₹999 deal.
Clear Value Perception
“First 3 for ₹999” is easier to understand than percentage discounts.
Works with Mixed Products
Handles combinations of different priced items seamlessly.