=== Profit Warden ===
Contributors: beralabs, kingbera
Tags: woocommerce, profit, margin, orders, analytics
Requires at least: 5.3
Tested up to: 7.0
Stable tag: 3.1.7
Requires PHP: 7.2
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Plugin to connect WooCommerce with the Profit Warden analysis backend.

== Description ==

Profit Warden is a connector plugin that sends WooCommerce order data to a separate analysis service. It calculates the real profit and margin for each order by considering product purchase costs, shipping costs, packaging, and payment gateway fees.

**⚠️ Important: External Service Required**
This plugin requires the external **Profit Warden Python service** to be running and accessible via a configurable API URL. Without this backend service, the plugin cannot function. You are responsible for setting up and hosting this service independently.

**Features:**

* Calculates real profit and margin for each WooCommerce order
* Accounts for purchase costs, shipping, packaging, and payment gateway fees
* Displays profit analysis directly on the WooCommerce order detail page
* Supports simple and variable products with individual purchase cost fields
* Sends periodic profit/loss reports via email using WP-Cron
* Alerts for orders sold at a loss
* Configurable API URL and cost parameters via Settings -> Profit Warden

**External Services**

This plugin relies on external services to calculate order profitability and provide marketing integrations. By default, it communicates with the **BeraTemplate API** (`https://api.beratemplate.com/calculate-profit`).

*   **What it does:** Calculates order margins, correlates UTM tracking data, and handles synchronization with Meta/Google Ads.
*   **What data is sent:** When enabled via the "Data Sync Consent" opt-in, it transmits WooCommerce order details (totals, shipping costs, items), customer billing email/name, and UTM marketing parameters triggered on order status changes or periodic reporting.
*   **Terms of Service:** [https://beratemplate.com/terms-of-service.html](https://beratemplate.com/terms-of-service.html)
*   **Privacy Policy:** [https://beratemplate.com/privacy-policy.html](https://beratemplate.com/privacy-policy.html)

*(Note: The API URL can be changed in the plugin settings to point to your own self-hosted backend service if desired).*

== Installation ==

1.  Upload the `profit-warden` folder to the `/wp-content/plugins/` directory.
2.  Activate the plugin through the 'Plugins' menu in WordPress.
3.  Go to Settings -> Profit Warden to configure the API URL and other cost parameters.
4.  Ensure your Profit Warden Python service is running and the API URL is correct.

== Frequently Asked Questions ==

= Does this plugin work without the Python service? =

No, this plugin requires the backend analysis service to function. It is designed to send data to it.

= Where do I set the product purchase cost? =

A "Purchase Cost (€)" field is added to the "General" tab of the product data section for simple and variable products.

== Screenshots ==

1. Profit Warden - Ads Integration Dashboard.
2. Database Tools and Configuration Check.
3. API & Email Configuration Settings.

== Videos ==

1. [youtube https://youtu.be/-LeIQ67hU98?is=YnewN-HrlfIKuOix]
2. [youtube https://youtu.be/yx2B6A0ekr8?is=FT_0Xgpp85SgFwbu]

== Changelog ==

= 3.1.7 =
* FEATURE: Added SVN AutoGen tools for release management.
* FIX: General code updates and readiness for publishing.

= 3.1.5 =
* COMPLIANCE: Removed trial limitations and paid plan triggers to ensure free tier compliance.
* COMPLIANCE: Enforced explicit opt-in data sync consent before any remote API health checks.
* COMPLIANCE: Ensured text domain is set to profit-warden for full I18N compatibility.

= 3.1.4 =
* FEATURE: Added Ads Integration Dashboard for Meta and Google Ads.
* FIX: Verified UTM tracking logic across checkouts.

= 3.1.2 =
* FIX: Resolved cookies mismatch in UTM tracking.
* FIX: Backward compatibility for legacy tracking cookies.

= 3.1.1 =
* FEATURE: Added Onboarding Setup Wizard for easy configuration.
* COMPLIANCE: Implemented explicit Opt-in Consent for data transmission to comply with WordPress.org guidelines.
* SECURITY: Added nonces and permission checks to all admin actions.
* FIX: Renamed assets for better unique prefixing.

= 2.2-beta =
* FIX: Corrected plugin version format in the header.
* FIX: Aligned text domain for internationalization.
* FEATURE: Added periodic reporting via WP-Cron.

== Upgrade Notice ==

= 3.1.5 =
Fixes critical compliance issues regarding data sync consent and removes leftover trial configurations.

= 3.1.4 =
Introduces the new Ads Integration Dashboard to monitor marketing performance directly from WordPress.

= 3.1.2 =
Fixes critical tracking issues with UTM parameters. Update recommended for accurate ad attribution.

= 3.1.1 =
Critical compliance updates and new onboarding flow. Please review your data sync consent settings.

= 2.2-beta =
This version introduces cron-based reporting and fixes minor compliance issues. Please review your settings under Settings -> Profit Warden after updating.