- Fix ISE 500 error on plugin activation: - Defer wc_get_logger() call in Logger class (lazy initialization) - Move plugin init to plugins_loaded hook with priority 20 - Remove invalid Google_Service_ShoppingContent_Reports instantiation - Migrate from deprecated Content API to new Merchant API: - Rewrite Google API class with direct REST calls - Implement JWT authentication using PHP OpenSSL - Use WordPress wp_remote_* functions for HTTP requests - Support Price Competitiveness reports for competitor pricing - Remove all Composer dependencies: - Delete vendor/ directory (~50 packages) - Delete composer.json and composer.lock - Remove setup scripts and related documentation - Plugin is now fully self-contained with no external dependencies Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
177 lines
5.6 KiB
Markdown
177 lines
5.6 KiB
Markdown
# Informatiq Smart Google Pricing
|
||
|
||
A production-ready WooCommerce plugin that automatically adjusts sale prices based on Google Merchant Center competitor data.
|
||
|
||
## Description
|
||
|
||
This plugin connects to the Google Merchant API to retrieve competitive pricing data and automatically updates your WooCommerce product prices to stay competitive while maintaining your desired profit margins.
|
||
|
||
## Features
|
||
|
||
- **Automated Daily Price Updates**: Schedule automatic price adjustments using WordPress cron
|
||
- **Google Merchant API Integration**: Uses the new Google Merchant API (replaces deprecated Content API)
|
||
- **No External Dependencies**: Self-contained plugin with no Composer requirements
|
||
- **Tax-Aware Pricing**: Handles both tax-inclusive and tax-exclusive pricing configurations
|
||
- **Minimum Margin Protection**: Never sell below your cost + minimum margin
|
||
- **In-Stock Only Processing**: Only updates products that are currently in stock
|
||
- **Comprehensive Logging**: Track all price changes with detailed logs
|
||
- **Manual Sync**: Test and trigger price updates manually from the admin panel
|
||
- **WooCommerce Cost of Goods Support**: Uses product cost data for margin calculations
|
||
|
||
## Requirements
|
||
|
||
- WordPress 5.8 or higher
|
||
- WooCommerce 5.0 or higher
|
||
- PHP 7.4 or higher
|
||
- PHP OpenSSL extension (for JWT authentication)
|
||
- Google Merchant Center account
|
||
- Google Service Account with Merchant API access
|
||
|
||
## Installation
|
||
|
||
1. Download the plugin
|
||
2. Upload to `/wp-content/plugins/informatiq-smart-google-pricing/`
|
||
3. Activate the plugin through the 'Plugins' menu in WordPress
|
||
4. Configure settings under WooCommerce > Smart Pricing
|
||
|
||
No Composer or external dependencies required - the plugin is fully self-contained.
|
||
|
||
## Configuration
|
||
|
||
### Google Merchant Center Setup
|
||
|
||
1. Create a Google Cloud Project
|
||
2. Enable the Merchant API
|
||
3. Create a Service Account and download the JSON key
|
||
4. Grant the service account access to your Merchant Center account
|
||
|
||
### Plugin Settings
|
||
|
||
1. Navigate to **WooCommerce > Smart Pricing**
|
||
2. Enter your Google Merchant ID
|
||
3. Paste your Service Account JSON key
|
||
4. Set your minimum profit margin percentage
|
||
5. Configure automation settings
|
||
6. Save settings and test the connection
|
||
|
||
## How It Works
|
||
|
||
1. **Daily Automation**: The plugin runs automatically based on your configured schedule
|
||
2. **Product Matching**: Matches WooCommerce products with Google Merchant Center via SKU/GTIN
|
||
3. **Competitive Analysis**: Retrieves competitive pricing data from Google's Price Competitiveness reports
|
||
4. **Price Calculation**:
|
||
- Calculates new price as: Competitor Price - Random Offset (0.05-0.20)
|
||
- Ensures price never goes below Cost + Minimum Margin
|
||
- Handles tax calculations based on WooCommerce settings
|
||
5. **Price Update**: Updates the product sale price in WooCommerce
|
||
6. **Logging**: Records all changes for auditing and review
|
||
|
||
## Tax Handling
|
||
|
||
The plugin intelligently handles both pricing configurations:
|
||
|
||
- **Prices Include Tax**: Sets sale price directly to match desired final price
|
||
- **Prices Exclude Tax**: Reverse-calculates base price to achieve desired final price after tax
|
||
|
||
## Minimum Margin Protection
|
||
|
||
The plugin ensures profitability by:
|
||
|
||
1. Checking product cost from WooCommerce Cost of Goods (`_wc_cog_cost` meta)
|
||
2. Falling back to regular price if cost is not set
|
||
3. Calculating minimum price as: `Cost × (1 + Minimum Margin %)`
|
||
4. Never setting prices below this minimum threshold
|
||
|
||
## Admin Interface
|
||
|
||
Access the admin panel at **WooCommerce > Smart Pricing** to:
|
||
|
||
- Configure Google API credentials
|
||
- Set pricing rules and margins
|
||
- Test API connection
|
||
- Run manual price syncs
|
||
- View sync schedule and status
|
||
- Review today's price updates
|
||
- Monitor logging and errors
|
||
|
||
## Logging
|
||
|
||
All price updates are logged with:
|
||
|
||
- Product ID and name
|
||
- Old and new prices
|
||
- Competitor price
|
||
- Timestamp
|
||
- Update message
|
||
|
||
Logs are stored in a custom database table and also written to WooCommerce logs for debugging.
|
||
|
||
## Cron Schedule
|
||
|
||
The plugin supports multiple update frequencies:
|
||
|
||
- Once daily (default)
|
||
- Twice daily (every 12 hours)
|
||
- Every 6 hours
|
||
|
||
## File Structure
|
||
|
||
```
|
||
informatiq-smart-google-pricing/
|
||
├── admin/
|
||
│ └── class-informatiq-sp-admin.php
|
||
├── assets/
|
||
│ ├── css/
|
||
│ │ └── admin.css
|
||
│ └── js/
|
||
│ └── admin.js
|
||
├── includes/
|
||
│ ├── class-informatiq-sp-google-api.php
|
||
│ ├── class-informatiq-sp-logger.php
|
||
│ ├── class-informatiq-sp-price-updater.php
|
||
│ └── class-informatiq-sp-scheduler.php
|
||
├── languages/
|
||
├── informatiq-smart-google-pricing.php
|
||
├── README.md
|
||
└── uninstall.php
|
||
```
|
||
|
||
## API Notes
|
||
|
||
This plugin uses the new Google Merchant API which replaces the deprecated Content API for Shopping. Key differences:
|
||
|
||
- **Base URL**: `https://merchantapi.googleapis.com`
|
||
- **Pricing**: Amounts are in micros (1,000,000 micros = 1 unit of currency)
|
||
- **Resource naming**: Uses hierarchical names like `accounts/{id}/products/{product}`
|
||
|
||
## Support
|
||
|
||
For support and documentation, visit [informatiq.services](https://informatiq.services)
|
||
|
||
## Author
|
||
|
||
**Mălin Cenușă**
|
||
- Website: [malin.ro](https://malin.ro)
|
||
- Company: [informatiq.services](https://informatiq.services)
|
||
|
||
## License
|
||
|
||
GPL v2 or later
|
||
|
||
## Changelog
|
||
|
||
### 2.0.0
|
||
- Migrated to Google Merchant API (from deprecated Content API)
|
||
- Removed Composer/vendor dependencies
|
||
- Self-contained plugin with direct REST API calls
|
||
- JWT-based authentication using PHP OpenSSL
|
||
|
||
### 1.0.0
|
||
- Initial release
|
||
- Google Merchant Center integration
|
||
- Automated daily price updates
|
||
- Tax-aware pricing logic
|
||
- Minimum margin protection
|
||
- Comprehensive logging
|
||
- Admin interface with manual sync
|