=== WebSkyLink Buy Together & Save ===
Contributors: vrvijendra007
Tags: woocommerce, frequently bought together, upsell, cross-sell, bundle
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.2
Requires Plugins: woocommerce
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Let customers buy related products together with a bundle discount, and add the whole set to the cart in one click.

== Description ==

Customers who buy a camera usually need a memory card and a case too. This plugin puts those products right next to the one being viewed, ticked and ready, with a running total and a single button that adds the whole set to the cart.

= How it works =

1. Edit a product and open Product data > Buy Together & Save.
2. Pick the products that go with it, or the categories and tags to pull them from.
3. Optionally set a bundle discount, for example 10% off when at least one suggestion is bought with it.
4. The box appears on the product page. Customers untick anything they do not want and add the rest in one click.

= Features =

Everything below is included, with nothing held back for a paid version.

**Choosing the suggestions**

* Link products by hand, in the order you want them shown.
* Link a variable product to let the customer pick its variation from a dropdown inside the box, or link one exact variation.
* Suggest products from chosen categories and tags, per product.
* Automatic suggestions from up-sells, cross-sells and related products, either only for products with nothing linked by hand, or always after the hand picked ones.
* **Order history suggestions:** suggest what customers really bought together. Paid orders are read once a day in the background, in small batches, and products that shared enough orders are suggested automatically. Choose how far back to read and how many shared orders count.
* An unlimited number of suggestions, or a set number.
* Random order, so a limited box rotates through a longer list.
* Suggestions ticked by default, or left for the customer to tick.
* Hide the box on individual products.
* Out of stock and unpurchasable products are left out automatically.

**Bundle discounts**

* Percentage or fixed amount off the whole set, main product included.
* A store wide default, overridable per product.
* A minimum number of suggestions before the discount applies, with a hint telling the customer how many more to add.
* The box shows the crossed out price and how much the customer saves.
* The discount shows as its own line in the cart, at checkout and on the order. It is checked against what is actually in the cart, so removing a product from the set removes the discount, and raising quantities counts complete sets only.
* Taxes are handled: the saving matches the figure shown in the box whether prices are displayed with or without tax.

**Variable products**

* Works on variable products: the box follows the options picked in the product's own form, updates its price and image, and only enables the button once a variation is chosen.
* Variable suggestions offer a dropdown of their variations, with prices and images updating as the customer picks.

**Display**

* Two main placements to choose from: a separate full width section above related products (the default), or a compact box right below the add to cart button. Also: below the product summary, below the product tabs, or at the bottom of the page. Or none, and place it yourself. In block themes, the separate section sits directly above the Related products block, at the same width.
* Two layouts for the full width box: product cards in a row joined with plus signs, with a tick box on each image, or a list with a thumbnail on each row. A separate panel shows the total, the saving and the button.
* A compact design for the box below the add to cart button: one row per product with a small image, and the total beside the button.
* Choose the image size.
* Customise the title, text above the list, labels, button text (with the number of products), savings text, hint and discount line.
* Customise the background, border, button, button text, button hover and savings colours.
* Use your own loading image while products are being added.
* The main product always stays in the set and cannot be unticked. Each product is added once.

**Cart**

* Adds the set over AJAX and refreshes the mini cart, or works as a plain form without JavaScript.
* After adding, stay on the page, go to the cart, or go straight to checkout.
* Each suggestion in the cart shows which product it was bought with.
* Cart page suggestions: for every product the customer added on its own, a box in the cart offers its linked products that are not in the cart yet, with the discount shown. Products added there join that product's set, so the bundle discount applies. Works on the classic cart page and the cart block.

**Analytics and reports**

* Counts box views, sets added to the cart, bundle orders, bundle revenue and the discount given, as daily totals with no personal data.
* A Reports tab with headline figures, a daily or weekly chart (with a table view), and a per product breakdown with add rates.
* Visits by shop managers are not counted, so testing the shop does not skew the figures.

**Page builders**

* A Frequently Bought Together block for the block editor, with a product search, live preview, and a cart mode. Works in block theme templates such as Single Product.
* An Elementor widget with the same options.

**Emails**

* Add a "Complete your set" block to chosen customer emails, such as Processing order and Completed order, with products bought together with what was ordered. Products already in the order are left out.

**Admin**

* A linked products screen lists every product with suggestions set, with a one click × to remove a single link and a bulk action to clear products completely.
* Bulk link: link the same products to every product in chosen categories at once, adding to or replacing existing links.
* CSV export and import of every product's links, categories, tags, discount and visibility, matched by product ID or SKU.
* Settings live under WooCommerce > Settings > Frequently Bought Together.
* When Webskylink Request a Quote is active, the linked products screen sits in the Webskylink Suite menu, otherwise under WooCommerce.

**Compatibility**

* Works with High Performance Order Storage (HPOS) and the block based cart and checkout.
* Translation ready, with WPML and Polylang support for the linked products, categories, tags and every text setting.
* Templates can be overridden from your theme.

= Shortcodes =

* `[webskylink_fbt product_id="123"]` shows the box for a product anywhere. Leave out product_id to use the product being viewed.
* `[webskylink_fbt_cart]` shows the cart page suggestions box, for example in a Shortcode block on the block based cart page.

The block and the Elementor widget offer the same two modes without a shortcode.

= For developers =

Copy `templates/frequently-bought-together.php` to `yourtheme/webskylink-fbt/frequently-bought-together.php` to change the markup. The email block templates are in `templates/emails/` and are overridden the same way.

Filters include `webskylink_fbt_suggestions`, `webskylink_fbt_candidate_ids`, `webskylink_fbt_supports_product`, `webskylink_fbt_is_available_item`, `webskylink_fbt_is_allowed_item`, `webskylink_fbt_discount_rule`, `webskylink_fbt_cart_discount`, `webskylink_fbt_location_hooks`, `webskylink_fbt_template_args`, `webskylink_fbt_email_suggestions` and `webskylink_fbt_setting`. The `webskylink_fbt_added_to_cart` action fires after a set is added.

== Installation ==

1. Upload the `webskylink-frequently-bought-together` folder to `/wp-content/plugins/`, or upload the zip through Plugins > Add New > Upload Plugin.
2. Activate the plugin.
3. Edit a product and open Product data > Buy Together & Save to link products.
4. Adjust the position, texts, colours and discount under WooCommerce > Settings > Buy Together & Save.

== Frequently Asked Questions ==

= The box does not appear on my product =

The box shows on simple and variable products that are published, in stock and purchasable, once at least one suggestion is available. Check that the linked products are in stock and purchasable themselves, that "Hide the box" is not ticked on the product, and that the position setting is not "Nowhere".

= Can customers change quantities in the box? =

No. Each product in the set is added once. Customers can change quantities in the cart as normal; the discount then counts complete sets only.

= Why does a variable suggestion not list one of its variations? =

Variations set to "Any" value for an attribute are left out of the dropdown, because the box offers one dropdown per product rather than one per attribute. Give the variation a specific value for every attribute, or link a different variation.

= Does the discount stack with coupons? =

Yes. The bundle discount is a separate line in the cart and coupons apply as usual.

= Does it work with the block based cart page? =

Yes. Adding to the cart, the discount and the cart page suggestions all work with the block based cart and checkout.

= How are order history suggestions worked out? =

Once a day, paid (processing and completed) orders from the period you choose are read in batches of 100 through WooCommerce's Action Scheduler, and the plugin counts how many orders contained each pair of products. Products that shared at least the number of orders you set are suggested, most frequent first. A new list only replaces the old one once it is complete. Rebuild it at any time from the Tools tab.

= Does the add to cart button work with page caching? =

Yes. Like WooCommerce's own add to cart, the box does not rely on a security token that a cached page could hold past its expiry.

== Changelog ==

= 1.3.0 =
* New: compact design for the box below the add to cart button: one row per product with a small image, and the total beside the button, made for the narrow column next to the product image.
* Improved: "Position on the product page" is now a clear choice, with the separate full width section and the compact box below the add to cart button listed first.
* Changed: the plugin is now called WebSkyLink Buy Together & Save, with the text domain webskylink-buy-together-save. Settings, product links, discounts and statistics are unchanged, and translations for the former text domain still load.

= 1.2.2 =
* Improved: the box adapts to the width it is placed in, not just the screen. In a narrow content column or the block editor, the total moves below the products instead of squeezing them.

= 1.2.1 =
* Fix: with many suggestions, the last card could wrap onto a row of its own; cards now stay in one row at equal widths, scrolling sideways when there are too many.
* Improved: shorter labels for the category and tag pickers on the product screen.

= 1.2.0 =
* New: cart page suggestions with the bundle discount. Every product added to the cart on its own gets a box offering its linked products; products added there join that product's set, so the discount applies. Works with the cart block as well as the classic cart page, and is on by default.

= 1.1.1 =
* New: "Above related products" position, now the default. In block themes the box sits directly above the Related products block at the same width, instead of running on from the product description.
* Improved: redesigned box, with product cards, a tick box on each image, a "This item" badge, a discount badge next to the title, and a separate panel for the total, saving and button.

= 1.1.0 =
* New: order history suggestions, built daily in the background from what customers actually bought together.
* New: analytics and a Reports tab with views, sets added, bundle orders, revenue, discount given, a chart and a per product breakdown.
* New: Frequently Bought Together block for the block editor, with product search and a cart mode.
* New: Elementor widget.
* New: "Complete your set" suggestions in chosen customer emails.
* New: bulk link products to every product in chosen categories.
* New: CSV export and import of links, categories, tags, discounts and visibility.
* Fix: the colour settings had no effect on the button inside WooCommerce pages, where WooCommerce's own button style is more specific.
* Fix: adding to the cart failed with "session expired" for guests on cached product pages.
* Fix: the per product discount amount did not show in the product editor on stores using a comma as decimal separator.
* Fix: the stylesheet and script still loaded on product pages after the box was switched off.
* Fix: a variable product's box placed away from its own page (shortcode, block, widget) had a button that could never be enabled; it now links to the product page to choose options.
* Fix: the shortcode found no product in some block theme templates.
* Fix: renaming the discount line no longer affects how the discount is identified on orders.

= 1.0.0 =
* Initial release.
