=== PromoTimer ===
Contributors: alin
Donate link: https://webdesign-profesional.com/promo-timer/
Tags: woocommerce, sale, countdown, promotions, ecommerce
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 7.4
Requires Plugins: woocommerce
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html


Schedule WooCommerce sale prices with start/end date + time, show a countdown, and display customizable promo messages.

== Description ==

**Promo‑Timer** lets you plan **time‑boxed promotions** for WooCommerce products, with **start/end date and time**, display a **live countdown** in the product page, and customize all **texts, emojis, and colors**. Works for **simple products** and **product variations**, each variation can be scheduled **independently**.

**Perfect for:** flash sales, limited‑time offers, seasonal discounts, and product launches.

**Highlights**
- 🕒 Schedule sales precisely: **start/end date + hour:minute**
- 🔥 Pre‑promo message: *"Promotion starts on DATE at TIME"*
- ⏳ Live countdown during promo: *"Hurry up! Promotion ends in: 12:02:45"*
- 💸 Under-price message during promo: *"Take advantage! This product is on promotion."*
- 🧼 Auto‑cleanup after expiry: removes promo meta and resets sale price
- 🎯 Full support for **variable products** (per variation settings)
- 🎨 Admin settings to customize **texts**, **emoji**, and **colors**
- 🌍 Fully translatable (.pot included)
- 🧰 Clean architecture, separated **assets/js** and **assets/css**

> **Dependencies**: Requires **WooCommerce** to be active.

**What it does not do (by design)**
- It does not override WooCommerce pricing logic; it augments it with time scheduling, messages and countdown. It will reset the sale price at expiry if the promo was active.

== Features ==

- Schedule sale prices with **date + time**
- Show **pre‑promo** notice with start date/time
- Show **countdown** and **under‑price** promo message while active
- Hide countdown automatically when promo ends and **reset sale price**
- Works with **simple** and **variable** products (independent per variation)
- **Admin settings page**: customize emoji, colors, all texts (placeholders supported)
- **Internationalization ready** (`/languages/promo-timer.pot`)
- Clean code structure: `/includes`, `/assets/css`, `/assets/js`

== Screenshots ==

1. Admin: Product (simple) – Promo date/time fields  
2. Admin: Product variations – Independent promo scheduling per variation  
3. Frontend (before start): “🔥 Promotion starts on DATE at TIME” above the price  
4. Frontend (active): countdown “Hurry up! Promotion ends in: 10:03:22”  
5. Frontend (active): under-price message “🔥 Take advantage! This product is on promotion.”  
6. Admin: Promo‑Timer Settings – texts, emoji, colors

== Installation ==

1. Upload the plugin folder `promo-timer` to `/wp-content/plugins/` or install the ZIP via **Plugins → Add New**.
2. Activate **Promo‑Timer** from **Plugins**.
3. Ensure **WooCommerce** is active.
4. (Optional) Go to **Settings → Promo‑Timer** to customize emoji, colors, and texts.
5. Edit a product:
   - For **simple products**: in **Product data → General → Pricing**, set:
     - **Promo Start Date**, **Promo Start Time (HH:MM)**
     - **Promo End Date**, **Promo End Time (HH:MM)**
   - For **variations**: in **Variations** tab, set the same fields **per variation**.

**Note:** The countdown appears on the **single product page**. The sale price visibility is handled by WooCommerce; Promo‑Timer adds logic and messages around it.

== Frequently Asked Questions ==

= Does it require WooCommerce? =
Yes. The plugin hooks into WooCommerce product/variation edit screens and the single product template.

= Will it work with variable products? =
Yes. Each variation has its **own** start/end date and time. The frontend countdown and messages update when a variation is selected.

= Does it change my theme templates? =
No template overrides. It uses standard WooCommerce hooks:
- `woocommerce_single_product_summary` (before and after price)
- `woocommerce_available_variation` (data for JS on variation change)

= Can I customize the texts and emoji? =
Yes. Go to **Settings → Promo‑Timer**. You can customize:
- Emoji (e.g. 🔥 ⏳ ⚡ 💥 🎉)
- Main color
- 3 texts:
  - Before promo: `Promotion starts on %date% at %time%`
  - During promo (label above timer): `Hurry up! Promotion ends in:`
  - Under price during promo: `Take advantage! This product is on promotion.`

= Is it translatable? =
Yes. The plugin is fully internationalized. A `.pot` file is included in `/languages`. Use tools like Loco Translate or Poedit.

= What happens when the promotion ends? =
A **WP‑Cron** task runs hourly to clean expired promotions:
- Deletes promo meta fields (`_pt_*`)
- Resets WooCommerce sale price
- The countdown disappears automatically (also triggers a page refresh on expiry)

== Developer Notes ==

Folder structure:
- `/includes`
- `/assets/css`
- `/assets/js`
- `/languages`

== Changelog ==

= 1.0.3 =
* Fix: After promotion expiry, product price was not displaying correctly on the product page
* Fix: Sale price was not fully removed from database after cleanup cron ran

= 1.0.2 =
* Fix: Sale price was showing on variable product parent even when promotion was not active
* Fix: Sale price was incorrectly applied in cart and checkout before campaign start time
* Fix: WooCommerce price cache was not cleared after promotion expiry - reduced price remained visible on product page
* Fix: Countdown was displaying "0d" and "0h" - these are now hidden automatically when value is zero
* Fix: Incorrect timezone on servers running UTC - replaced time() with wp_timezone()
* Fix: Product page was showing cached content after promotion expiry on LiteSpeed/WP Rocket/W3TC cache plugins
* Fix: Promotion start and expiry now reflect immediately on page refresh without manual cache clearing
* New: Promo badge now appears below product title in shop/category/archive pages
* New: "Campaign starts on..." message now also displayed in product listing pages
* CSS: Badge forced onto new line regardless of price width

= 1.0.1 =
* Initial release on WordPress.org