=== Smart Product Sort ===
Contributors: plgnplay, freemius
Tags:              woocommerce, product sorting, catalog, sort order, shop
Requires at least: 6.5
Tested up to:      6.9
Requires PHP:      7.4
WC requires at least: 7.1
WC tested up to:   10.5.3
Stable tag:        1.1.0
License:           GPL-2.0-or-later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Define custom product sorting rules for your WooCommerce catalog — per-category, priority-based, toggle on/off instantly.

== Description ==

Smart Product Sort is a WooCommerce plugin that gives store owners full control over how products appear in shop and category pages. Instead of relying on default WooCommerce sorting, you can create custom sorting rules and apply them globally or to specific categories — all without writing a single line of code.

**The Problem**

WooCommerce's built-in sorting is limited. Store owners often need to:

* Show newest products first in one category
* Show best sellers first in another
* Prioritize higher-priced items in premium collections
* Apply a consistent default sort across the entire shop
* Change sorting quickly without editing theme files

Smart Product Sort solves all of this through a straightforward admin interface.

**Features**

* **Unlimited sorting rules** — Sort by name, price, popularity, rating, date, random, or menu order.
* **Global or per-category** — Apply a rule to the whole shop or assign it to a specific product category. Category rules override global ones automatically.
* **Priority system** — Lower number means higher importance. When multiple rules exist, the priority system determines which one wins — no conflicts.
* **On/off toggle** — Activate or deactivate any rule instantly. Test changes or handle seasonal sorting without deleting anything.
* **Customer choice preserved** — When a customer manually selects a sort option from the WooCommerce dropdown, their choice always takes priority.
* **Lightweight** — Runs a single database query per page load. No heavy operations, no performance impact.
* **HPOS compatible** — Fully compatible with WooCommerce High-Performance Order Storage.

**How It Works**

1. Navigate to **WooCommerce > Smart Product Sort** in your admin dashboard.
2. Click **Add Sort Rule**.
3. Choose the sort criteria (price, name, date, popularity, rating, random, or menu order).
4. Optionally assign the rule to a specific product category.
5. Set a priority number and activate the rule.

Sorting applies automatically on the frontend from that point on. Category-specific rules take precedence over global rules. When a customer visits a category with its own rule, that rule applies. Otherwise, the global rule is used as a fallback.

**Use Cases**

* Fashion stores showing premium items first
* Electronics stores prioritizing best sellers
* Seasonal stores highlighting new arrivals
* Large catalogs with many categories needing different sort orders
* Stores that frequently update product positioning

== Installation ==

1. Upload the `smart-product-sort` folder to `/wp-content/plugins/`.
2. Activate through **Plugins > Installed Plugins**.
3. Make sure WooCommerce is installed and active.
4. Go to **WooCommerce > Smart Product Sort** to add your first rule.

== Frequently Asked Questions ==

= Does this plugin require WooCommerce? =

Yes. Smart Product Sort is built specifically for WooCommerce and requires it to be installed and active.

= Can I set different sort rules for different categories? =

Yes. You can create category-specific rules that override the global default. If no category-specific rule exists, the global rule is used as a fallback.

= What happens if a customer manually selects a sort option? =

The customer's manual selection always takes priority. The plugin only controls the default sort order when no manual selection has been made.

= Will this plugin slow down my store? =

No. The plugin runs a single lightweight database query to determine the active rule and modifies the existing WooCommerce query arguments. There is no additional overhead.

= How does the priority system work? =

Each rule has a priority number. A lower number means higher importance. If multiple rules could apply, the one with the lowest priority number wins. This prevents conflicts and keeps sorting predictable.

= Is this compatible with WooCommerce HPOS? =

Yes. The plugin declares full compatibility with High-Performance Order Storage.

== Screenshots ==

1. Smart Product Sort admin dashboard — clean card-based layout with all sort rules at a glance.
2. Add Sort Rule modal — choose sort criteria, category, priority, and activate with a toggle switch.
3. Edit Sort Rule modal — modify existing rules with pre-filled fields and save instantly.

== Changelog ==

= 1.1.0 =
* Pro: In-Stock First sorting — push out-of-stock products to the bottom automatically.
* Pro: On-Sale First sorting — show discounted products first.
* Pro: Reviews sorting — sort by number of reviews.
* Pro: Rule duplication — clone any rule with one click.
* Pro: Rule import/export — export rules as JSON, import from file.
* Pro: Upgrade to Pro teaser for free users.
* Improved sort order labels for clarity.
* Freemius SDK integration for Pro licensing and updates.

= 1.0.1 =
* Redesigned admin interface with enterprise-grade UI.
* Improved table layout, modal design, and status badges.
* Added sort order indicators and empty state design.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.1.0 =
Pro features: In-Stock First sorting, On-Sale First, Reviews, rule duplication, import/export.

= 1.0.1 =
Redesigned admin interface with a cleaner, modern look.

= 1.0.0 =
Initial release of Smart Product Sort.
