Skip to main content

How to do a 3x2 sale ?

Hi.

I want to offer 3x2 for certain category in my store so the cheapest options is free. What is the best option to configure it?

Thanks! :)

Hi! FluentCart Pro’s Dynamic Pricing supports bulk discounts, but it can’t automatically make the cheapest of three items in a category free.

Maybe in a future update :)

So, you will need custom code.

Part of the magic of Fluent is that you can make this feature available by yourself πŸ™‚

For this exact 3-for-2 offer, enable FluentCart Pro > Settings> Features & Addon > Dynamic Pricing.

Then, you may want to try adding the PHP snippet below.

Replace sale-category with your category slug. It makes the cheapest eligible unit free once there are three eligible units in the cart, with a limit of one free unit per order.

add_filter('fluent_cart/cart/item_dynamic_discount', function ($items) {
$category = 'sale-category';
$quantity = 0;
$cheapestKey = null;
$cheapestPrice = PHP_INT_MAX;

foreach ($items as $key => $item) {
    $productId = (int) ($item['post_id'] ?? 0);
    $units = (int) ($item['quantity'] ?? 0);
    $price = (int) ($item['unit_price'] ?? 0);

    if (!$productId || $units < 1 || $price <= 0
        || ($item['other_info']['payment_type'] ?? '') === 'subscription'
        || !has_term($category, 'product-categories', $productId)) {
        continue;
    }

    // Skip the promotion if an eligible line already has a discount.
    if (!empty($item['discount_total'])) {
        return $items;
    }

    $quantity += $units;
    if ($price < $cheapestPrice) {
        $cheapestPrice = $price;
        $cheapestKey = $key;
    }
}

if ($quantity < 3 || $cheapestKey === null) {
    return $items;
}

$line = &$items[$cheapestKey];
$line['manual_discount'] = $cheapestPrice;
$line['discount_total'] = $cheapestPrice;
$line['line_total'] = (int) $line['subtotal'] - $cheapestPrice;

return $items;

}, 20);

I’d test a full order in staging before using it in a live store.

Jorge de los ReyesΒ Great! Gracias, Jorge!