=== RuleForge – Fees & Discounts ===
Contributors: chillichalli
Author: ChilliChalli
Author URI: https://chillichalli.com
Plugin URI: https://wordpress.org/plugins/ruleforge-fees-discounts/
Tags: woocommerce, fees, discounts, surcharges, cart rules
Requires at least: 6.3
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.2.14
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Add smart fees and discounts to WooCommerce. Create rules based on cart total, location, payment method, and more.

== Description ==

**Stop leaving money on the table.** RuleForge gives you complete control over fees and discounts in your WooCommerce store with powerful, condition-based rules.

Whether you need to add payment gateway surcharges, offer location-based discounts, or create complex promotional rules, RuleForge makes it simple.

= Why Store Owners Love RuleForge =

* **Set it and forget it** – Rules run automatically on every order
* **No coding required** – Visual rule builder with JSON power when you need it
* **Lightning fast** – Optimized queries that won't slow down your checkout
* **WooCommerce native** – Seamlessly integrates with your existing setup

= Real-World Use Cases =

**Payment Gateway Fees**
Offset credit card processing costs by adding a 2-3% surcharge for card payments while keeping cash-on-delivery free.

**Location-Based Pricing**
Add handling fees for remote areas, or offer discounts to customers in your local region.

**Minimum Order Incentives**
"Spend $100 and get $10 off" – Encourage larger orders with automatic discounts.

**First-Time Buyer Discounts**
Welcome new customers with exclusive discounts on their first order.

**Tiered Discounts**
The more they buy, the more they save. Create progressive discount tiers based on cart value.

= Free Features =

* **Unlimited Rules** – Create as many active fee and discount rules as you need
* **Flexible Conditions** – Cart subtotal, billing country, payment gateway, user roles, products, day of week, first order detection
* **Powerful Actions** – Percentage fees, fixed fees, percentage discounts with optional caps
* **Priority Control** – Define which rules run first
* **Lightweight** – No bloat, just the features you need

= Pro Features =

* **Tiered Discounts & Fees** – Reward bigger carts: buy 3+ save 10%, 6+ save 20%. Build the tier table visually and tier by cart quantity or subtotal, as a percentage or fixed amount
* **Stack Mode** – Create exclusive rules that stop processing when matched
* **Import/Export** – Backup rules or copy between sites with JSON export
* **Mock Cart Preview** – Test your rules before going live
* **REST API** – Preview endpoint for headless or custom integrations
* **Priority Support** – Direct help when you need it

= Example Rules =

**2% Credit Card Surcharge (capped at $10)**
`Condition: Payment gateway = stripe`
`Action: Add 2% fee, max $10`

**Free Shipping Threshold Discount**
`Condition: Subtotal >= $75`
`Action: -$5 discount labeled "Almost Free Shipping!"`

**UK Customer Handling Fee**
`Condition: Country = GB`
`Action: Add $3 fixed fee`

**Tiered Bulk Discount (Pro)**
`Action: Tiered discount — buy 3+ = 10% off, 6+ = 20% off, 12+ = 30% off`
Build it with the visual **Tiered Discount Builder**, or with JSON in the Actions box:
`[{"type":"tiered_discount","basis":"quantity","mode":"percent","tiers":[{"min":3,"value":10},{"min":6,"value":20},{"min":12,"value":30}],"label":"Bulk discount"}]`

= Built for Performance =

RuleForge is designed with performance in mind:

* Efficient database queries with proper indexing
* Minimal footprint – only loads on relevant pages
* No external API calls during checkout

= Developer Friendly =

* Clean, well-documented codebase following WordPress coding standards
* Extensible architecture for custom conditions and actions
* Full REST API access (Pro)

== Installation ==

1. Upload `ruleforge-fees-discounts` to `/wp-content/plugins/`
2. Activate through **Plugins** menu
3. Go to **WooCommerce → RuleForge** to create your first rule

**Quick Start:**
1. Click "Add New" to create a rule
2. Add conditions (e.g., subtotal >= 50)
3. Add actions (e.g., 5% discount)
4. Enable the rule and save

Your rule is now live and will automatically apply to matching orders.

== Frequently Asked Questions ==

= Do I need WooCommerce? =
Yes, RuleForge is built specifically for WooCommerce and requires it to function.

= Will this slow down my checkout? =
No. RuleForge is optimized for performance with efficient queries and caching. It adds negligible overhead to your checkout process.

= How many rules can I create? =
There is no limit. The free version lets you create as many active fee and discount rules as you need.

= How are rules processed? =
Rules run in the order you set with the Priority field (lowest number first). Every matching rule is applied. RuleForge Pro adds exclusive Stack Mode, which stops processing after the first matching rule when you want only one rule to apply.

= Can I add fees to specific payment methods? =
Yes! This is one of the most popular use cases. Add a percentage or fixed fee when customers choose specific payment gateways like Stripe, PayPal, or Cash on Delivery.

= Does it work with my theme? =
RuleForge works entirely in the backend and doesn't affect your theme. Fees and discounts appear in the standard WooCommerce cart and checkout.

= Can I offer discounts based on cart total? =
Absolutely. Create rules like "10% off orders over $200" or "$15 off when you spend $100+".

= Can I create bulk or tiered discounts? =
Yes, with RuleForge Pro. The Tiered Discount Builder lets you set thresholds like "buy 3+ save 10%, 6+ save 20%, 12+ save 30%" — tiered by cart quantity or subtotal, applied as a percentage or a fixed amount, with an optional maximum cap. The highest matching tier is applied automatically.

= Is there a money-back guarantee? =
Yes, Pro licenses include a 14-day money-back guarantee through Freemius.

== Screenshots ==

1. Rule editor – Define conditions and actions with flexible JSON syntax
2. Rule settings – Control priority and enable/disable rules
3. Pro features – Import/Export rules and preview with mock cart data

== External services ==

This plugin connects to the Freemius licensing service (https://freemius.com) when the site administrator activates the plugin, opts in to usage tracking, activates a Pro license, or checks for plugin updates. Freemius is used to deliver license activation, opt-in analytics (only when the administrator explicitly consents on the activation screen), and Pro update delivery.

What data is sent, and when:

* On activation: the site URL, plugin version, WordPress version, PHP version, and (if the administrator opts in) the administrator's name and email address.
* During license activation and renewal checks: the license key and site URL.
* On periodic update checks: the plugin version and site URL.

No customer or order data is ever sent to Freemius.

The Freemius service is provided by Freemius, Inc. Their terms and privacy policy apply:

* Terms of Service: https://freemius.com/terms/
* Privacy Policy: https://freemius.com/privacy/

== Changelog ==

= 0.2.14 =
* HARDENING: Restricted the rule post type to shop managers/administrators at the capability level (previously its access relied only on the meta-save check), aligning the edit-screen permissions with the data permissions.
* HARDENING: Added direct-access (ABSPATH) guards to the remaining internal class files. No functional change.

= 0.2.13 =
* COMPLIANCE: Removed the active-rule limit entirely. The WordPress.org version now supports unlimited active rules and is fully functional, in line with Guideline 5. Any rules previously disabled by the old limit can simply be re-enabled.
* The remaining Pro-only features (tiered discount tables, exclusive stack mode, import/export, mock-cart preview, and the REST preview endpoint) are separate add-on functionality and are not part of the WordPress.org build.

= 0.2.12 =
* Housekeeping: cleared a Plugin Check warning (prefixed an internal catch variable). No functional change.

= 0.2.11 =
* COMPLIANCE: Reworked premium gating to the WordPress.org-compliant model — the free version is fully self-contained (the rule limit and stack mode use Freemius's premium-build flag, not a live license check).
* COMPLIANCE: Removed automatic deactivation of other plugins.
* Prefixed the rule post type to `ruleforge_rule` (existing rules are migrated automatically).

= 0.2.10 =
* Maintenance release (packaging/slug alignment for the WordPress.org listing). No functional change.

= 0.2.9 =
* Renamed to "RuleForge – Fees & Discounts" (slug `ruleforge-fees-discounts`) to meet WordPress.org naming rules. No change to your rules or settings.

= 0.2.8 =
* Internal: annotated two intentional priority-ordering queries so automated checks report cleanly. No functional change.

= 0.2.7 =
* COMPAT: Declared compatibility with WooCommerce High-Performance Order Storage (HPOS) and the block-based cart & checkout, clearing the WooCommerce "incompatible plugin" notice.

= 0.2.6 =
* Renamed the plugin for WordPress.org naming compliance. No change to your rules or settings.

= 0.2.5 =
* FIX: Plugin no longer fatals on case-sensitive filesystems (Linux/WordPress.org) — the class autoloader now preserves directory case. This affected all non-Windows/macOS hosts.
* FIX: The "Add New Rule" screen no longer returns a 403 ("link expired") — the rule save handler now ignores auto-draft/non-form saves before the nonce check.
* NEW: Installing the Pro version now auto-deactivates the free version (Freemius `set_basename`) to prevent both running at once.

= 0.2.4 =
* FIX: Corrected Freemius initialization to the WordPress.org-compliant model (`is_premium`, `premium_suffix`, `wp_org_gatekeeper`) so the free version is generated and gated correctly.
* Updated Freemius SDK to 2.13.1.

= 0.2.3 =
* COMPLIANCE: Removed in-plugin "Upgrade to Pro" calls-to-action and locked-feature lists from the menu page, rule editor, and rule-limit notice. Pro discovery is now handled via the Freemius Account menu.
* COMPLIANCE: Rule-limit notice rewritten as a factual notice (no marketing copy or upgrade link).
* COMPLIANCE: Added explicit `@fs_premium_only` header marker so Pro-only source files are stripped from the WordPress.org distribution.
* COMPLIANCE: Documented the Freemius external service in readme.txt (data sent, terms, privacy).
* FIX: Removed invalid `is_premium_only` key from Freemius init; added `is_org_compliant` flag and explicit menu integration.

= 0.2.2 =
* NEW: Unified the free and Pro editions into a single freemium plugin
* NEW: Pro tier with Stack Mode, Import/Export, and Preview
* IMPROVED: Performance optimizations for admin pages

= 0.2.1 =
* Fixed coding standards violations
* Initial public release

== Upgrade Notice ==

= 0.2.14 =
Security hardening: rule editing is now restricted to shop managers/administrators at the capability level. No action needed.

= 0.2.13 =
The active-rule limit has been removed — the free version now supports unlimited rules. Re-enable any rules that were previously disabled.

= 0.2.3 =
WordPress.org compliance pass. Removes in-plugin upgrade prompts; rule data is unchanged.

== Licensing ==

RuleForge is open source under GPLv2 or later.

Pro features are unlocked via [Freemius](https://freemius.com) licensing with a 14-day money-back guarantee.

**Ready to take control of your WooCommerce pricing?** [Get RuleForge Pro](https://chillichalli.com/ruleforge)
