=== Codvia – COD Fee & Cash on Delivery Rules for WooCommerce ===
Contributors: codrulesdev
Tags: cash on delivery, cod, cod fee, payment gateway, woocommerce
Requires at least: 6.6
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Add a properly taxed COD fee, or hide cash on delivery by city, postcode or order amount — and tell the customer why.

== Description ==

**Codvia COD Rules** manages WooCommerce's Cash on Delivery gateway with rules you can read: *charge a fee*, *hide COD*, or *always allow COD* when conditions match. What it does:

* **The fee is taxed properly.** Choose taxable or not, and which tax class, per rule or as a default. The tax shows separately in the cart, checkout, emails and invoices, exactly like any other WooCommerce fee.
* **Thresholds never count the fee itself.** "COD only under 400" means the items total, not items plus the COD fee. Choose whether shipping and tax are part of the amount rules look at.
* **Works on the block checkout and the classic checkout.** The fee appears the moment the customer picks Cash on delivery, and disappears when they change their mind or their address.
* **Tells the customer why.** When a rule hides COD, the customer sees your message where the payment options are, instead of a silently missing option. Each rule can carry its own message.
* **Unlimited cities and postcodes, free.** Paste a list, one per line. Wildcards (`Al *`, `1234*`) and numeric ranges (`10000-19999`) work. Spelling variants are folded before matching, so "Al-Rayyan", "al rayyan" and "AL RAYYAN" are one entry, and so are "الريان" and "الريّان" whatever the hamza, taa-marbuta or alef-maqsura. List a city in both scripts to catch both — the ready-made lists for Qatar, Saudi Arabia, UAE, Kuwait, Bahrain, Oman and Egypt already include both, and insert with one click.
* **The fee shows in emails, invoices and the order.** It is a real WooCommerce fee line, tagged with the rule that created it, and every order gets a note explaining the decision.
* **Explainable.** The scenario tester shows, rule by rule and condition by condition, why a given customer gets a fee or loses COD. Test unsaved rules before you publish them.
* **One-click import from Smart COD.** If you used *Smart COD for WooCommerce*, your restrictions, fees and messages are rebuilt as rules in a few seconds. Your existing settings are not touched.

= Conditions (free) =

Order amount, item quantity, city, postcode, state/region, country, shipping method, customer role.

= Pro =

* **Date & time schedules** – restrict COD or change the fee on certain days, hours or date ranges (Ramadan and Eid delivery windows, with the Hijri date shown next to the Gregorian one).
* **Product, category, shipping class, cart weight and coupon conditions.**
* **Customer history** – e.g. hide COD for first-time buyers, or waive the fee for repeat customers.
* **Manual and phone orders** – the fee line is added, updated or removed when an admin order set to COD is recalculated.
* Priority support.

= How rules run =

Rules run top to bottom. The first matching *hide* rule hides COD and stops. The first matching *fee* rule sets the fee. An *allow* rule that matches protects COD from any hide rule below it. Every rule can require all of its conditions, or any of them.

= For developers =

Filters: `crfw_condition_types`, `crfw_match_condition`, `crfw_decision`, `crfw_cart_fee`, `crfw_gateway_id`, `crfw_presets`, `crfw_rules`, `crfw_context_from_cart`, `crfw_context_from_order`, `crfw_pro_active`. REST namespace `crfw/v1`. The block checkout receives the decision under `extensions["cod-rules"]` on the Store API cart response.

== Installation ==

1. Install and activate the plugin. WooCommerce 8.6 or newer is required.
2. Make sure the Cash on delivery gateway is enabled under WooCommerce → Settings → Payments.
3. Go to WooCommerce → COD Rules and add your first rule, or import your Smart COD settings from the Import tab.
4. Use "Test a scenario" to check what a customer in a given city, with a given order amount, will see.

== Frequently Asked Questions ==

= Why is the fee not taxed? =

Check that taxes are enabled in WooCommerce → Settings → General, that a tax rate exists for the customer's location, and that the rule (or the default in Settings) is set to *Taxable*. The scenario tester shows whether a fee is taxable and which class it uses.

= The customer's city has a different spelling in Arabic. Will it match? =

Yes. Case, punctuation, diacritics and common letter variants (ة/ه, أ/ا, ى/ي) are folded before matching, and you can add both spellings to a list anyway. Use `*` for a wildcard.

= Does the "order amount" include the COD fee? =

Never. It is the items total after discounts, optionally plus shipping and tax, as chosen in Settings.

= Does it work with the block-based checkout? =

Yes. COD Rules is built for the block checkout first and also supports the classic shortcode checkout and the "pay for order" page.

= Can I use it for a gateway other than the built-in Cash on delivery? =

Yes. Set the gateway id in Settings → Advanced. Any gateway with that id is managed the same way.

= Will it conflict with Smart COD or another COD fee plugin? =

Run one at a time. After importing from Smart COD, deactivate Smart COD so the fee is not charged twice.

= What happens on uninstall? =

The plugin's settings and rules are removed. Order notes and the fee lines on existing orders are kept, because they are part of your order history.

== Screenshots ==

1. The rule editor: what happens, and when.
2. The scenario tester explains every rule and condition.
3. A taxed COD fee on the block checkout.
4. The message customers see when a rule hides Cash on delivery.
5. One-click import from Smart COD.
6. The decision recorded on each order.

== Changelog ==

= 1.0.1 =
* Renamed for clarity: the plugin is the same, the title now says what it does.
* Corrected the description of Arabic city matching. Spelling variants fold within each script; list a city in both scripts to match both. The ready-made GCC lists already contain both.


= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.0.0 =
Initial release.
