=== CodeAtoz Campaign Manager for WooCommerce ===
Contributors: codeatoz
Tags: woocommerce, flash sale, countdown timer, promotions, discount
Requires at least: 6.0
Tested up to: 6.9
Stable tag: 1.3.1
Requires PHP: 7.4
WC requires at least: 7.0
WC tested up to: 9.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Run flash sales & WooCommerce promotions with countdown timers, urgency badges, and a clean campaign dashboard. No recurring fees.

== Description ==

CodeAtoz Campaign Manager for WooCommerce is a lightweight WooCommerce plugin built for small and growing stores that want to run effective flash sales without complex marketing tools or recurring fees.

From a single, clean admin screen you can:

* Create multiple **campaigns** (Flash Sale, Weekend Deal, Clearance)
* Apply **percentage or fixed amount discounts** across your entire catalog – or limit discounts to selected product categories – without touching product data
* Schedule campaign **start and end dates** – including weekend promos and short flash drops
* Show a sticky **announcement bar with countdown timer** on all storefront pages
* Add **urgency badges** on product cards and an urgency message in the cart
* See all campaigns in a simple **dashboard list** with status badges and quick actions

All pricing logic uses standard WooCommerce price filters – no direct database writes – so your original prices remain safe. The plugin is fully translatable and follows WordPress.org coding and security best practices.

### Key Features

* **Flash Sale Engine**
  * Percentage or fixed discounts on all products, or only on selected product categories
  * Works with simple and variable products
  * Leaves original product prices intact (no direct DB changes)

* **Smart Campaign Scheduling**
  * Set start and end date/time for each campaign
  * Scheduled campaigns auto-activate and auto-expire
  * Cron health check with admin notice if WP-Cron or Action Scheduler is not running

* **Conversion-Focused Storefront UI**
  * Sticky announcement bar with live countdown timer
  * Urgency badges on product cards (Flash Sale, Weekend Deal, Clearance)
  * Cart urgency message with live countdown
  * Product page “sale ends” message under the add to cart button

* **3 Built-In Templates**
  * ⚡ **Flash Sale** – 20% off, red bar, 24-hour flash sale style
  * 🔥 **Weekend Deal** – 15% off, orange bar, ideal for Friday–Sunday promos
  * 💥 **Clearance** – 30% off, purple bar, 7-day clearance style
  * One-click template selection pre-fills the campaign form (you can still adjust all fields)

* **Performance & Compatibility**
  * Uses the WordPress Transients API to cache the active campaign
  * WooCommerce HPOS compatible
  * No external API calls and no tracking in the free version

### Who Is It For?

CodeAtoz Campaign Manager for WooCommerce is perfect for:

* Small WooCommerce stores running **occasional flash sales**
* Brands that want a **simple promotion tool** instead of heavy marketing suites
* Store owners who care about **performance, safety and clean code**

== Installation ==

1. **Upload the plugin**
   * Download the plugin ZIP and upload via `Plugins → Add New → Upload Plugin`, or
   * Upload the `codeatoz-campaign-manager` folder to `/wp-content/plugins/` via FTP.

2. **Activate the plugin**
   * Go to `Plugins → Installed Plugins` and click **Activate** on CodeAtoz Campaign Manager for WooCommerce.

3. **Verify WooCommerce**
   * Make sure WooCommerce is installed and activated. If not, the plugin will show an admin notice.

4. **Create your first campaign**
   * Go to `WooCommerce → Smart Campaigns`.
   * Click **Add New Campaign**.
   * Either pick a **template** at the top or fill the form manually:
     * Campaign Name
     * Type (Flash Sale, Weekend Deal, Clearance)
     * Discount Type & Value
     * Announcement Bar Text
     * Bar Background Color & Timer Color
     * Start Date & Time, End Date & Time
     * Status (Draft, Scheduled, Active)
   * Click **Create Campaign**.

5. **Test on the storefront**
   * Visit your shop and product pages.
   * When a campaign is active you should see:
     * Storefront announcement bar with countdown
     * Sale prices and badges on products
     * Urgency messages in the cart and on product pages

== Usage ==

### Creating a new campaign

1. Go to `WooCommerce → Smart Campaigns` and click **Add New Campaign**.
2. (Optional) Choose a **template** at the top (Flash Sale, Weekend Deal, Clearance) to prefill common settings.
3. Fill out the **Campaign Details** card:
   * **Campaign Name** – internal name shown in the admin list.
   * **Campaign Type** – Flash Sale, Weekend Deal, or Clearance (used for labels and badges).
   * **Announcement Bar Text** – the message shown in the storefront bar.
   * **Status** – Draft, Scheduled, Active or Expired.
4. Configure the **Discount Settings** card:
   * **Discount Type** – Percentage or Fixed Amount.
   * **Discount Value** – required; for example `20` for 20% or `15` for a 15‑unit fixed discount.
   * **Limit to Categories** – leave blank to apply to all products, or select one or more product categories to target only those items.
5. Configure the **Schedule & Appearance** card:
   * **Start Date & Time** – when the campaign should begin (optional; leave empty to start immediately when set to Active).
   * **End Date & Time** – when the campaign should end (optional; leave empty for open‑ended campaigns).
   * **Quick fill** buttons – 24 hours, This Weekend, or Next 7 Days to speed up date entry.
   * **Bar Background Color** & **Countdown Timer Color** – control the storefront bar appearance; the live preview updates as you type.

### Advanced options

These options appear in the Discount Settings or Schedule & Appearance areas:

* **Test Mode** (checkbox) – when enabled, the campaign is only visible and applied to users who can manage WooCommerce (store admins). Use this to preview the bar, badges and discounts before going live.
* **Minimum Cart Value** – if set above zero, the discount only applies when the cart subtotal is at least this amount.
* **Exclude Products Already On Sale** – if enabled, products that already have a WooCommerce sale price keep their own sale and are not further discounted by the campaign.
* **Social Proof Text** – small line of text shown in the announcement bar (for example “Over 500 orders placed this week!”).

### How discounts are applied

* Discounts are applied **dynamically via WooCommerce price filters** – the plugin never modifies product prices in the database.
* Only **one active campaign** is used for pricing at a time (the most recently created active campaign).
* If **Limit to Categories** is empty, discounts and urgency UI apply to **all products** (subject to minimum cart value, test mode and exclude‑on‑sale settings).
* If one or more categories are selected, discounts and urgency elements (badge, price HTML, product urgency text) only appear on products belonging to those categories.

### Scheduled campaigns

* Set **Status = Scheduled** and fill **Start Date** and/or **End Date**.
* The plugin uses **Action Scheduler** to:
  * Automatically switch the campaign to **Active** at the start time.
  * Automatically switch it to **Expired** at the end time.
* If WP‑Cron or Action Scheduler are not running correctly, the Smart Campaigns admin screen shows a clear warning with a link to documentation.

== Frequently Asked Questions ==

= Does this plugin modify my product prices in the database? =

No. CodeAtoz Campaign Manager for WooCommerce uses standard WooCommerce price filters to apply discounts at runtime. Your original product prices remain unchanged in the database.

= Can I run more than one campaign at the same time? =

The plugin supports multiple campaigns but only one active campaign is applied
to pricing at a time — the most recently created active campaign takes priority.
Future Pro versions may add advanced targeting and multiple concurrent campaigns.

= What happens if WP-Cron or Action Scheduler is not working? =

The plugin checks WP-Cron and Action Scheduler health on the Smart Campaigns admin screen. If something looks wrong (cron disabled or Action Scheduler not run recently), it shows a clear warning with a link to the official WordPress cron documentation.

= Will this slow down my store? =

CodeAtoz Campaign Manager for WooCommerce caches the active campaign using the Transients API for 60 seconds, so WooCommerce product price lookups don’t hit the database on every request. The frontend assets are small and loaded only on WooCommerce pages.

= Does it work with WooCommerce HPOS (High-Performance Order Storage)? =

Yes. The plugin declares compatibility with WooCommerce HPOS using `\WooCommerce\Utilities\FeaturesUtil::declare_compatibility()`.

= Can I customize the templates or add my own? =

Yes. The three default templates are defined in PHP and exposed through the `scm_campaign_templates` filter. Developers can hook into this filter to add, remove or modify templates in custom code or a Pro add-on.

= Does the free version call any external APIs or track my store? =

No. The free version does not make any outgoing HTTP requests or track usage. All logic runs inside your WordPress and WooCommerce installation.

== Changelog ==

= 1.3.1 =
* Fixed: Campaign form now correctly redirects to edit page after saving — no more empty form on create.
* Fixed: Admin page background and styling now apply correctly (CSS class mismatch resolved).
* Fixed: Timezone handling for campaign dates — dates entered in site timezone are now saved and displayed correctly.
* Fixed: Announcement bar now loads on all frontend pages, not just WooCommerce pages.

= 1.3.0 =
* Added: Full campaign form fields now visible in free version — Discount Type, Discount Value, Status, Bar Text, Start/End Dates, Bar Color, Timer Color, Test Mode.
* Added: Date quick-pick presets — 24 Hours, This Weekend, Next 7 Days.
* Added: Live status dot on campaign status field (green/grey/blue/red).
* Added: Future start date warning — shows clear notice when campaign is Active but start date is in the future.
* Added: Browse all 50 PRO templates button shown when Pro is active.
* Fixed: Frontend announcement bar now loads on all pages (homepage, blog, custom pages), not just WooCommerce pages.
* Fixed: Timezone bug — campaign dates now correctly saved and displayed in the WordPress site timezone.
* Fixed: Action Scheduler jobs now fire at correct local time regardless of server timezone.
* Fixed: Test mode checkbox now saves correctly.
* Fixed: Pro upgrade links updated to correct URL.
* Improved: New single-column full-width admin UI matching Pro plugin design.
* Security: index.php silence files added to all subdirectories.

= 1.1.0 =
* Added test mode for previewing campaigns as admin before going live.
* Added minimum cart value condition — discount only applies when cart reaches threshold.
* Added exclude on-sale items option — protects already-discounted products.
* Added social proof text field displayed in the announcement bar.
* Improved admin UI with live preview, campaign templates, and modern card layout.
* Fixed scheduled campaign auto-activation and expiration.

= 1.0.0 =
* Initial release.
* Campaign CRUD admin UI with WP_List_Table.
* Flash sale discount engine using WooCommerce price filters.
* Storefront announcement bar with countdown timer.
* Action Scheduler integration for scheduled campaigns.
* Urgency badges, cart message and product page urgency text.
* 3 built-in templates for quick campaign setup.

== Upgrade Notice ==

= 1.1.0 =
This release adds test mode, minimum cart value, exclude on-sale items, and social proof fields. A database migration runs automatically on upgrade to add the new columns.

= 1.0.0 =
First public release.

