WooCommerce Price History & Sale Compliance

Complete Documentation & Implementation Guide

Overview

The WooCommerce Price History & Sale Compliance plugin ensures your WooCommerce store complies with consumer protection laws like the EU's Omnibus Directive by automatically tracking product price history and displaying the lowest price in the last 30 days on product pages during sales.

πŸ€– Automatic Compliance

Meets EU Omnibus Directive requirements without manual intervention

πŸ“Š Professional Display

Shows compliance information and optional price charts professionally

πŸ”„ Variable Product Support

Properly handles variations with separate price tracking

πŸ’° One-time Purchase

No recurring fees or subscriptions

System Requirements:
  • WordPress 5.8 or higher
  • WooCommerce 6.0 or higher
  • PHP 7.4 or higher
  • MySQL 5.6 or higher

Installation

Method 1: WordPress Admin Upload

  1. Download the plugin zip file
  2. Go to Plugins > Add New in your WordPress admin
  3. Click Upload Plugin
  4. Choose the zip file and click Install Now
  5. Click Activate Plugin

Method 2: Manual Installation

  1. Extract the plugin files to /wp-content/plugins/wc-price-history-compliance/
  2. Go to Plugins in WordPress admin
  3. Find "WooCommerce Price History & Sale Compliance" and click Activate
Post-Installation: After activation, the plugin automatically creates the price history database table and begins tracking price changes on product updates.

Configuration

Navigate to WooCommerce > Settings > Price History to configure the plugin.

Compliance Settings

Enable 30-Day Lowest Price Message

Default: Yes

Description: Shows compliance message on product pages during sales

Legal Note: Required for EU Omnibus Directive compliance

Message Text

Default: "Lowest price in the last 30 days: %s"

Usage: Use %s as placeholder for the formatted price

Examples:

  • German: "Niedrigster Preis in den letzten 30 Tagen: %s"
  • French: "Prix le plus bas dans les 30 derniers jours: %s"
  • Spanish: "Precio mΓ‘s bajo en los ΓΊltimos 30 dΓ­as: %s"

Custom Period (Days)

Default: 30 days

Range: 1-365 days

Legal Note: EU directive requires 30 days minimum

Law/Compliance Tooltip

Default: Empty (disabled)

Example: "Price complies with EU Omnibus Directive 2019/2161 requiring display of lowest price in 30 days prior to discount."

Price Chart Settings

Enable Price History Chart

Default: Yes

Note: Chart only displays when meaningful price history exists (2+ data points)

Features

Automated Price Tracking

The plugin automatically records price changes when:

  • Product regular price is updated
  • Product sale price is set or modified
  • Bulk price updates are performed
  • Scheduled sales begin or end
Technical Implementation: Hooks into woocommerce_update_product and woocommerce_save_product_variation to ensure all price changes are captured.

Compliance Message Display

When Displayed:

  • Only appears during active sales (when sale price < regular price)
  • Shows the lowest price recorded in the specified period
  • Updates automatically when prices change

Price History Charts

Chart Features

  • Interactive line chart using Chart.js
  • Responsive design for mobile devices
  • Currency formatting matches WooCommerce settings
  • Shows 2x the compliance period for better context

Variable Product Handling

  • AJAX-powered chart updates when variations are selected
  • Each variation maintains separate price history
  • Seamless user experience with loading states

Admin Reports

Access via WooCommerce > Price History:

  • Complete price change log
  • Product search functionality
  • Pagination for large datasets
  • Export capabilities for compliance audits

Technical Details

Database Schema

The plugin creates a custom table wp_wc_price_history:

CREATE TABLE wp_wc_price_history (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    product_id bigint(20) NOT NULL,
    price decimal(19,4) NOT NULL,
    date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    PRIMARY KEY (id),
    KEY product_id (product_id)
);

File Structure

/wc-price-history-compliance/
β”œβ”€β”€ wc-price-history-compliance.php    (Main plugin file)
β”œβ”€β”€ includes/
β”‚   β”œβ”€β”€ class-price-tracker.php        (Price tracking logic)
β”‚   β”œβ”€β”€ class-display-handler.php      (Frontend display)
β”‚   β”œβ”€β”€ class-admin-reports.php        (Admin interface)
β”‚   β”œβ”€β”€ class-admin-settings.php       (Settings page)
β”‚   └── class-install-handler.php      (Activation/deactivation)
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ chart.js                   (Frontend chart functionality)
β”‚   β”‚   └── admin.js                   (Admin interface scripts)
β”‚   └── css/
β”‚       β”œβ”€β”€ frontend.css               (Frontend styling)
β”‚       └── admin.css                  (Admin styling)
β”œβ”€β”€ languages/                         (Translation files)
└── readme.txt                        (WordPress readme)

WooCommerce Compatibility

  • HPOS Compatible: Declares compatibility with High Performance Order Storage
  • WooCommerce Blocks: Works with classic and block-based themes
  • Multisite: Supports WordPress multisite installations
  • Caching: Compatible with popular caching plugins

Performance Considerations

Database Optimization

Optimized with proper indexing and prepared statements

Caching Strategy

Price history data is cached for frontend display

AJAX Loading

Asynchronous loading for variable product charts

Minimal Impact

Price tracking only occurs during product updates

Troubleshooting

Common Issues

Compliance Message Not Showing

  1. Verify the product is actually on sale (sale price < regular price)
  2. Check that "Enable 30-Day Lowest Price Message" is enabled in settings
  3. Ensure there's price history data (product must have been updated since plugin activation)

Price Charts Not Displaying

  1. Confirm "Enable Price History Chart" is enabled
  2. Check browser console for JavaScript errors
  3. Verify Chart.js is loading (check network tab in browser dev tools)
  4. Ensure the product has at least 2 price history entries

Variable Products Not Working

  1. Clear any page caching
  2. Check that variations have separate price history entries
  3. Verify AJAX requests are succeeding (check browser network tab)

Missing Price History Data

  • Price tracking begins after plugin activation
  • Historical prices before activation are not automatically imported
  • Ensure WooCommerce hooks are not being blocked by other plugins

Debug Mode

Add this to wp-config.php for detailed logging:

define('WCPC_DEBUG', true);

Developer Guide

Hooks and Filters

Filters

wcpc_lowest_price_message_text

Customize the compliance message display:

add_filter('wcpc_lowest_price_message_text', function($message, $product, $lowest_price) {
    return '<div class="custom-compliance">' . $message . '</div>';
}, 10, 3);

wcpc_price_history_chart_data

Modify chart data before display:

add_filter('wcpc_price_history_chart_data', function($data, $product_id) {
    // Customize chart data
    return $data;
}, 10, 2);

wcpc_compliance_period_days

Dynamically adjust the compliance period:

add_filter('wcpc_compliance_period_days', function($days, $product) {
    // Return different periods based on product category
    return $days;
}, 10, 2);

Actions

wcpc_price_recorded

Triggered when a new price is recorded:

add_action('wcpc_price_recorded', function($product_id, $price, $date) {
    // Custom logic when price is recorded
}, 10, 3);

Custom Styling

Override default styles by targeting these CSS classes:

/* Compliance message */
.wcpc-lowest-price-message {
    /* Your custom styles */
}

/* Chart container */
.wcpc-chart-container {
    /* Your custom styles */
}

/* Law tooltip */
.wcpc-law-tooltip {
    /* Your custom styles */
}

Database Access

Access price history data programmatically:

global $wpdb;
$table_name = $wpdb->prefix . 'wc_price_history';

$price_history = $wpdb->get_results($wpdb->prepare(
    "SELECT * FROM $table_name WHERE product_id = %d ORDER BY date DESC",
    $product_id
));