=== BePlus Discounts for Contact Form 7 ===
Contributors: lenguyendev
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: contact form 7, coupons, discounts, pricing, payments

Adds coupon and discount functionality to Contact Form 7 forms and updates a final amount field that payment addons can consume.

== Description ==

BePlus Discounts for Contact Form 7 helps you add coupon and discount support to Contact Form 7 forms without turning Contact Form 7 into a payment processor.

It is designed for forms that already calculate or collect an original amount and need to apply a coupon before a payment addon reads the final amount.

= What It Does =

* Validates coupon codes
* Applies fixed or percentage discounts
* Updates a final amount field inside the Contact Form 7 submission
* Tracks coupon usage after successful submissions
* Supports date windows, active/inactive status, quantity rules, and usage limits
* Works with payment addons that can read a final amount field

= Core Features =

* Fixed amount and percentage discounts
* Start date and expiry date support
* Active and inactive coupon states
* Usage limit tracking
* AJAX coupon validation
* Server-side recalculation before submission completes
* Custom `[cf7_discount_apply]` tag with tag generator support
* Final amount field updates for payment addon compatibility

= Before You Install =

This plugin requires:

* WordPress
* Contact Form 7
* A Contact Form 7 form that includes amount-related fields

This plugin does not process payments by itself. It prepares a validated final amount so your payment addon can use it.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/beplus-discounts-for-contact-form-7/`.
2. Activate Contact Form 7.
3. Activate BePlus Discounts for Contact Form 7.
4. Go to `CF7 Discounts > Settings`.
5. Review or change the field names used by the plugin.
6. Go to `CF7 Discounts > Coupons` and create your coupon codes.
7. Edit your Contact Form 7 form and add the required fields and apply button.
8. If you use a payment addon, configure it to read the final amount field instead of the original amount field.
9. Test the form with a valid coupon and an invalid coupon before using it on a live site.

== Usage ==

= 1. Configure Field Names =

Open `CF7 Discounts > Settings` and confirm the field names you want to use.

Default field names:

* Coupon field: `coupon_code`
* Quantity field: `qty`
* Original amount field: `amount`
* Final amount field: `final_amount`
* Discount amount field: `discount_amount`
* Discount message field: `discount_message`

= 2. Create A Coupon =

Open `CF7 Discounts > Coupons` and add a coupon with the settings you need, such as:

* Coupon code
* Fixed or percentage discount
* Active status
* Start date
* Expiry date
* Usage limit
* Minimum quantity
* Minimum total

= 3. Add The Fields To Your Contact Form 7 Form =

Example form markup using the default field names:

`[text coupon_code]`

`[number qty min:1 "1"]`

`[hidden amount "100"]`

`[hidden final_amount "100"]`

`[hidden discount_amount "0"]`

`[hidden discount_message ""]`

`[cf7_discount_apply "Apply Discount"]`

`[submit "Pay Now"]`

If your form does not use quantity-based coupon rules, you can omit the quantity field.

= 4. Connect Your Payment Addon =

If you use a payment addon, point it to the final amount field, not the original amount field.

The plugin recalculates the final amount on the server before Contact Form 7 completes submission, which helps prevent tampering.

== Frequently Asked Questions ==

= Does this plugin process payments? =

No. It only validates coupons and updates a final amount field for payment addons.

= Which payment addons are supported? =

It is gateway-agnostic. Configure your payment addon to read the final amount field.

= Which field should my payment addon use? =

Use the final amount field, which is `final_amount` by default unless you changed it in Settings.

= Do I need to add hidden fields to my form? =

Yes. At minimum, your form should include the original amount field, final amount field, discount amount field, discount message field, and the coupon field.

= What does the `[cf7_discount_apply]` tag do? =

It adds the apply button and the frontend behavior used to validate a coupon and update the discount summary.

= Can I change the field names? =

Yes. Go to `CF7 Discounts > Settings` and change the field names there. Your Contact Form 7 form and payment addon must use the same names.

= What happens if AJAX validation is disabled? =

The frontend will not validate coupons through AJAX, but server-side validation still protects the final amount during submission.

= What happens if a coupon is invalid? =

If invalid submission blocking is enabled, the form submission can be prevented and the coupon field will show the validation message.

= When is coupon usage counted? =

Usage is only counted after Contact Form 7 completes a successful submission.

= Can I use fixed discounts and percentage discounts? =

Yes. Each coupon can be configured as either a fixed amount discount or a percentage discount.

= Can I limit coupons by date or usage count? =

Yes. Coupons can use start dates, expiry dates, and usage limits.

= Can I use this without a payment addon? =

Yes. You can still use it to calculate discounts in a Contact Form 7 workflow, but the plugin itself does not charge customers.

= Why is my discount not applied? =

Common reasons include:

* the coupon code is inactive
* the coupon has expired
* the usage limit has been reached
* the amount or quantity fields do not match your Settings field names
* your form is using the original amount field instead of the final amount field

== Changelog ==

= 1.0.0 =
* Initial release.
