=== Product Bundles and Gift for WooCommerce ===
Contributors: catcodestudio
Tags: woocommerce, bundle, free gift, cart discount, buy x get y
Requires at least: 5.6
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Product bundles at a special price, a "Frequently bought together" block, a free gift above an order total, tiered order-total discounts and N+1 deals.

== Description ==

Two proven ways to raise the average order value — sell in sets and give a present for spending more. This plugin does both, without a separate bundle product type and without rewriting the theme.

= Product bundles =

* A set of two or more products: a special bundle price, a percentage discount or a fixed amount off.
* A "Frequently bought together" block on the page of every product in the set: images, names, prices, the total before and after the discount.
* One click adds the whole bundle to the cart.
* The discount is added as its own line in the cart and order totals, so the shopper sees exactly what they saved on.
* A bundle fires as soon as all of its products are in the cart, no matter how they got there. Two complete bundles mean a double discount.
* The discount never exceeds the value of the bundle itself.

= Free gift above an order total =

* A cart total threshold above which a gift product is added to the cart automatically.
* The gift quantity is locked to 1 and the line cannot be removed by hand.
* As soon as the total drops below the threshold, the gift disappears on its own.
* A progress hint in the cart: "Spend N more and get ...".
* A "Gift" badge on the cart line and on the order item.

= Cart discounts: order total and N+1 =

* Tiered order-total discount: "from 2000 — 5%, from 5000 — 10%". The highest tier reached wins; a percentage or a fixed amount.
* "Buy N, get M" deals (2+1, 3+1, the second at 50% off). Units are sorted from the most expensive down and the cheapest in each group is discounted, so an expensive item never goes free next to a cheap one.
* Limit a rule to the whole catalogue, chosen categories (subcategories included) or chosen products; optionally skip products already on sale.
* Stack deals with the order-total discount, or apply only the single biggest saving.
* Limit a rule to N units: the order-total discount is then priced on the N most expensive eligible units only (the threshold still counts the whole cart), a deal stops after N discounted units.
* A cart hint: "Add N more and get 10% off".
* Every discount is its own named line in the cart and in the order.

= Compatibility =

* Classic cart and checkout as well as the block-based ones (Store API) — the bundle discount and the gift are recalculated the same way in both.
* HPOS (custom order tables).

= Pro features =

* An unlimited number of bundles and gift thresholds.
* Conditions: product category, tag, user role.
* Several gifts on one threshold — the shopper picks one.
* A schedule for the promotion (active from / to).
* Unlimited order-total discounts and N+M deals, limited to customer roles and dates.
* A promotion label ("2+1") on the product page.
* Margin floor for coupons: coupons (and, optionally, the cart discount rules) never take a product below its cost plus a minimum margin. The cost comes from a "Cost" field on the product or variation, or from WooCommerce "Cost of goods sold" when that feature is on. Products without a cost can get a plain "no more than N% off" cap instead.
* Rule priority.
* Product variation support, both inside bundles and as a gift.

A fresh install is simply the free tier: one bundle, one gift threshold, one order-total discount and two N+1 deals, working for as long as you like. Nothing switches itself on. The Pro features are shown where they belong, greyed out, and unlock either with a licence key or with a 7-day trial you start yourself — one click, an e-mail address, no card. The licence is annual (1–5 years) and includes updates and support for that term.

= Requirements =

* WooCommerce 6.0 or newer
* PHP 7.4+

The plugin interface is fully translated into Ukrainian. / Інтерфейс плагіна повністю перекладено українською.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/product-bundles-and-gift-for-woocommerce/`
2. Activate it in the "Plugins" menu
3. Go to WooCommerce → Набори та подарунки (Bundles and gifts)
4. For a bundle: enable the card, pick 2 or more products, choose the discount type and its value
5. For a gift: enable the card, set the total threshold and the gift product

== Frequently Asked Questions ==

= Do I have to create a separate "bundle" product? =

No. A bundle is made of ordinary catalogue products; their stock and prices stay untouched.

= Does the discount apply if the shopper added the products one by one? =

Yes. The only condition is that every product of the bundle is in the cart.

= What happens when the shopper removes one product of the bundle? =

The discount line disappears from the totals and the remaining products stay in the cart at their regular prices.

= Can the gift quantity be changed, or the gift removed? =

No. The quantity is locked to 1, the remove button is hidden for that line, and the Store API marks it as non-editable. The gift only goes away when the cart total falls below the threshold.

= Does the gift work in the block-based cart? =

Yes. It is added while the totals are being calculated, and the Store API recalculates them on every request.

= How do I set several thresholds — one gift from 1000, another from 2000? =

That is a Pro feature. Add two thresholds; the one with the highest amount among those reached wins.

= Which amount is the gift threshold measured against? =

The cart line totals at their own prices, excluding the gift itself and excluding shipping.

== Screenshots ==

1. Bundle settings.
2. Gift thresholds and the extra conditions.
3. The "Frequently bought together" block on the product page.
4. The gift and the progress hint in the cart.

== Changelog ==

= 1.3.0 =
* New: "Discount at most on N units" for every cart discount rule. An order-total discount is priced on the N most expensive eligible units (like "Limit usage to X items" of WooCommerce coupons), while the threshold is still reached by the whole eligible cart. An N+M deal stops once N units got their discount.
* New (Pro): margin floor for coupons. WooCommerce coupons of the standard types (percentage, fixed cart, fixed product) stop at the product's floor price: cost ÷ (1 − minimum margin). Several coupons together, and "apply sequentially", are respected. Optionally the cart discount rules are held by the same floor, after the coupons.
* New: a "Cost" field on simple products and variations (hidden and ignored when WooCommerce "Cost of goods sold" is on — then only its value counts; the field value is kept). Products without a cost can be limited by "no more than N% off".
* The cart discount stays before the CatCode loyalty points in the totals, so points pay for the already discounted cart.
* Translations: Russian added; English (UK) updated.

= 1.2.2 =
* Fix: a variable product (for example a T-shirt in S/M/L) chosen as the gift is now really added to the cart — its default variation when that one is in stock, otherwise the first variation in stock. Before, the gift was silently skipped while the cart still said "Your gift is already in the cart".
* Fix: the "gift is already in your cart" message only shows when the gift line is actually there — not when the product is out of stock or has no available variation.
* Variation attributes set to "any" are filled with the first option, so the order says which size or colour was given away.
* Pro: when the first gift on the list cannot be added (out of stock), the next available one from the list is handed over instead of none.
* The gift settings now say which variation the customer will get and warn when the chosen product cannot be added (out of stock, no available variation, grouped or external product).

= 1.2.1 =
* Licensing: a purchased licence now stays yours. Once our server confirms a paid key, the Pro features keep working after the licence term ends and while catcode.com.ua is unreachable — the term covers updates and support. No answer from the licence server switches a purchase off; only releasing the key or entering a different one does.
* The 7-day trial is still a trial: when it ends, Pro switches off, also while the server is unreachable. A shop that tried Pro and then bought a key is no longer shown as being on a trial.

= 1.2.0 =
* New: cart discounts — tiered order-total discounts (percentage or fixed amount) and "buy N, get M" deals with a per-cart limit, category / product scope and an "exclude products on sale" switch.
* New: choose whether deals stack with the order-total discount or only the biggest saving applies.
* New: "Add N more and get X off" hint in the classic and block cart.
* New (Pro): unlimited discount rules, customer roles, a schedule and a promotion label on the product page.
* The English (UK) translation now covers the licence screen as well.

= 1.1.0 =
* The Pro trial no longer starts by itself. A fresh install is the free tier until the owner clicks "Try Pro for 7 days" and receives a real key by e-mail.
* Licence keys are now verified against catcode.com.ua (activate on save, re-check once a day, 14-day offline grace) instead of being accepted offline.
* Pro settings stay visible in their own place, greyed out, with a badge and one line explaining what each of them does.
* Saving the settings no longer wipes the licence key or the stored Pro values.
* One dismissible notice, shown only after a bundle discount or a gift has actually fired — dismissed once, gone for good.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.2.2 =
A variable product chosen as the gift is now really added to the cart (default or first in-stock variation), and the cart no longer congratulates on a gift that is not there.

= 1.2.1 =
A purchased licence keeps the Pro features after its term ends. An existing key learns whether it is a purchase or a trial at its next daily check.

= 1.2.0 =
Adds order-total discounts and N+1 deals. Nothing is switched on after the update: the example rules ship disabled.

= 1.1.0 =
The automatic 7-day Pro trial is gone: nothing switches itself on any more. Start the trial yourself when you want it.

= 1.0.0 =
Initial release.
