=== Tradewind International Fees and Coupons ===
Contributors: bloodweb
Tags: woocommerce, import duty, tariff, coupons, shipping
Requires at least: 5.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 4.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Charge import duties and offer discount codes by country or by continent in WooCommerce, with per-rule shipping and order-value conditions.

== Description ==

Set a fee or a discount code against a region, and let the region be either a
single country or a whole continent. An order to Zimbabwe can owe an
Africa-wide import duty and still use a code you wrote for Zimbabwe alone.

Every rule carries its own conditions, so a fee or a code can apply only above
a certain order value, or only when a particular shipping method was chosen.

The plugin is free, calls nothing on the internet and stores no customer data.
It reads the destination on the order in front of it and applies your rules.

= Regions =

A rule belongs to a region, and a region is either a continent or a single
country. A country picks up its continent's rules as well as its own:

    Africa (all countries)
      Fee     Import duty, 5.5%, any shipping method
      Coupon  FREESHIP, $40, only with STD - International Tracked

    Zimbabwe
      Coupon  ZIMBABWE, $100, only on orders over $100

An order to Zimbabwe owes the Africa-wide import duty, and may use either the
Africa-wide FREESHIP code or Zimbabwe's own, whichever suits it.

Continent membership comes from WooCommerce itself, so it stays correct without
a bundled country table going stale.

= How fees combine =

Two fees on the SAME region always stack. Germany carrying 10% VAT and a $100
import fee charges both: a $100 order becomes $210. Two fees entered against
one country are two things owed, not a choice.

When a country and its continent BOTH have fees, the store decides, under
WooCommerce -> Fees and Coupons:

* **Stack** - every matching fee is charged
* **Highest only** - only the single largest matching fee
* **Country first** - the country's fees, falling back to the continent's
* **Continent first** - the continent's fees, falling back to the country's

Each fee appears as its own line in the cart, so a customer can see what they
are being charged for.

= Coupons =

Codes are created as real WooCommerce coupons, so they are typed into the usual
box, appear in reports and behave normally everywhere else. What WooCommerce
cannot express natively, which is the region, the shipping method and the
order-value condition, is enforced by this plugin.

"Stackable coupons" decides whether a customer who qualifies for several of
these codes may use more than one. Coupons from other plugins are never
affected.

Codes you remove here are never deleted from WooCommerce, because past orders
reference them.

= Explaining a fee to the customer =

Each fee can carry a "What is this?" note. When it has one, a "?" appears
beside that fee in the cart and checkout totals, and clicking it opens the note
in a row directly underneath. A fee with no note gets no "?".

The note is plain text written on the settings screen, so it can say what the
charge is for in the store's own words rather than leaving a customer to guess
at a line item they did not expect.

On the classic cart and checkout the note opens in a row directly under its
fee. The Cart and Checkout blocks offer no hook on an individual fee row, so
there the notes gather in a short "About these charges" list under the order
summary, in the same order as the fees above them.

= Shipping costs =

Three independent switches, because the answer differs per store:

* **Include shipping in fee calculations** - a 5% fee on goods, or goods plus postage
* **Include shipping in coupon discounts** - a 10% code off goods, or off the lot
* **Include shipping in order value conditions** - "over $100" before or after postage

= Moving over from our earlier plugins =

This replaces two plugins of ours that asked the same question, which is where
is this order going, and answered it two different ways. Tariff Manager knew
about countries. Regional Coupon Manager knew about lists of countries. Neither
knew about continents, and neither could say "only with this shipping method"
or "only above this order value".

On activation the plugin imports whatever those two left behind. Their own
options are read, never written, so deactivating and going back is possible. A
coupon that covered five countries becomes that code against five regions.

Tariff Manager's global shipping-method and cart-value settings become per-rule
conditions, which is where they belong now that every rule carries its own. A
store that set both a minimum and a maximum cart value keeps the minimum.

== Installation ==

1. Install and activate WooCommerce first. This plugin does nothing without it
   and will say so on the plugins screen.
2. Upload the plugin through Plugins -> Add New -> Upload Plugin, or install it
   from the WordPress.org directory.
3. Activate it. If Tariff Manager or Regional Coupon Manager were ever set up
   on this site, their rules are imported now and a notice says so.
4. Go to WooCommerce -> Fees and Coupons, add a region, and give it a fee or a
   code.

== Frequently Asked Questions ==

= Does this replace WooCommerce's own coupons? =

No. It creates real WooCommerce coupons, so customers type them into the normal
coupon box and they show up in WooCommerce reports like any other. The plugin
only adds the conditions WooCommerce cannot express on its own: the region, the
shipping method and the order value.

= If I delete a code here, is the WooCommerce coupon deleted too? =

No. Past orders reference their coupons, so removing a code here stops it being
offered and enforced but leaves the WooCommerce coupon in place.

= Where does the list of countries in each continent come from? =

From WooCommerce. Nothing is bundled, so the mapping cannot drift out of date
as WooCommerce updates.

= Does the plugin send anything to an external service? =

No. There are no outbound requests, no analytics and no accounts. Fees and
coupon rules are stored in your own WordPress options table.

= A country and its continent both have a fee. Which one is charged? =

Whichever you chose under WooCommerce -> Fees and Coupons: stack both, take the
highest only, or prefer one level and fall back to the other. Two fees on the
same region always stack regardless.

= Does this work with the cart and checkout blocks? =

Yes, all of it. Fees and coupon rules are applied while the cart is calculated,
so they hold on the blocks exactly as they do on the classic templates.

The notes are placed differently, because the blocks give no hook on an
individual fee row. On the classic templates a note opens directly beneath its
fee. On the blocks the notes gather in a short "About these charges" list under
the order summary, in the same order as the fees.

= I used Tariff Manager or Regional Coupon Manager. Do I lose my settings? =

No. They are imported when you activate this plugin, and the old options are
left untouched so you can go back.

== Screenshots ==

1. Global settings: how country and continent fees combine, coupon stacking, and which totals include shipping.
2. A region with its own fees and coupon codes, each with its shipping-method and order-value conditions.
3. Two fees stacking in the classic cart totals, an EU-wide VAT and Germany's own handling charge, with the "What is this?" note opened underneath.
4. The same two fees on the Cart block, with their notes gathered under the order summary.

== Changelog ==

= 4.3.0 =
* Added extension points so an add-on can put its own fields on a rule and have them saved, narrow when a rule applies, and change the amount a percentage is worked out on: `ifc_rule_fields`, `ifc_sanitize_rule`, `ifc_conditions_met` and `ifc_fee_base`.
* Each fee now records which region charged it, so an add-on can report on it after the order is made.
* The settings screen fires `ifc:rules-added` when a rule or region is added, so add-on fields can set themselves up on the new copy.

= 4.2.0 =
* The "What is this?" notes now work on the Cart and Checkout blocks, which previously showed a fee with no explanation at all.
* Notes are listed in the same order as the fees they explain.
* Fixed a fatal on PHP 7.4, which the plugin claims to support: a WordPress 5.9 function was being called unconditionally.
* Coupon sync failures now go to WooCommerce -> Status -> Logs instead of the PHP error log.

= 4.1.0 =
* Each fee can now carry a "What is this?" note, shown from a "?" beside the fee in the cart and checkout totals.
* The note renders in the amount cell when JavaScript is unavailable, so it is never hidden entirely.

= 4.0.0 =
* First release of the merged plugin, replacing Tariff Manager and Regional Coupon Manager.
* Regions can now be a whole continent, with continent membership read from WooCommerce.
* Every fee and coupon carries its own shipping-method and order-value conditions, instead of one global setting.
* Added the choice of how country and continent fees combine: stack, highest only, country first or continent first.
* Settings from both predecessor plugins are imported on activation and left in place.

== Upgrade Notice ==

= 4.3.0 =
Adds extension points for add-ons. Nothing changes for existing rules and there is nothing to reconfigure.

= 4.2.0 =
Fee notes now appear on the Cart and Checkout blocks, where they were missing entirely. Also fixes a fatal on PHP 7.4. Nothing to reconfigure.

= 4.1.0 =
Fees can now explain themselves in the cart with an optional "What is this?" note. No settings change and nothing to redo after updating.
