Skip to content

Instantly share code, notes, and snippets.

@TanvirHasan19
Created November 12, 2025 03:24
Show Gist options
  • Select an option

  • Save TanvirHasan19/0c9e46840b6b27ee08ea8ae387f3a2b3 to your computer and use it in GitHub Desktop.

Select an option

Save TanvirHasan19/0c9e46840b6b27ee08ea8ae387f3a2b3 to your computer and use it in GitHub Desktop.
Sale Price & Language Fixes

Developer Quick Reference: Sale Price & Language Fixes

Quick Fix Summary

Sale Price Validation

File: classes/class-get-products.php
Lines: 2883-2916
What it does: Validates sale prices before including in feeds

Language Translation

File: includes/Integrations/WPML.php (Elite)
Lines: 262-291, 288, 291
What it does: Fixes WPML language switching for product feeds


Common Scenarios

Scenario 1: Sale Price Still Showing After Expiry

Check:

  1. Verify sale end date is set: $product->get_date_on_sale_to()
  2. Check current timezone: current_time( 'timestamp' )
  3. Verify validation logic is running (add debug log)

Debug Code:

// Add to sale price validation section
error_log( 'Sale Price Check - Product ID: ' . $product->get_id() );
error_log( 'Sale Price: ' . $sale_price );
error_log( 'Regular Price: ' . $regular_price );
error_log( 'Sale From: ' . ( $sale_from ? $sale_from->format( 'Y-m-d H:i:s' ) : 'none' ) );
error_log( 'Sale To: ' . ( $sale_to ? $sale_to->format( 'Y-m-d H:i:s' ) : 'none' ) );
error_log( 'Current Time: ' . date( 'Y-m-d H:i:s', $current_time ) );
error_log( 'Sale Valid: ' . ( $sale_valid ? 'yes' : 'no' ) );

Scenario 2: Language Not Switching

Check:

  1. WPML is active: is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' )
  2. WPML support enabled: get_option( 'adt_enable_wpml_support' ) === 'yes'
  3. Language set in feed: $feed->wpml
  4. Products have translations

Debug Code:

// Add to set_language_before_processing()
error_log( 'WPML Language Switch - Feed ID: ' . $feed->id );
error_log( 'Selected Language: ' . $lang_code );
error_log( 'Current Language Before: ' . $sitepress->get_current_language() );
error_log( 'Current Language After: ' . $sitepress->get_current_language() );

// Add to set_product_query_language()
error_log( 'Query Args Language: ' . $lang_code );
error_log( 'Suppress Filters: ' . ( $args['suppress_filters'] ? 'true' : 'false' ) );

Scenario 3: Discount Plugin Interference

Location: class-get-products.php lines 3033-3078

Issue: FlyCart discount plugin may override validated sale prices

Solution: Add validation after discount plugin calculation:

// After line 3077, add:
if ( isset( $product_data['sale_price'] ) && $product_data['sale_price'] > 0 ) {
    $regular_price = $product_data['regular_price'] ?? 0;
    if ( $product_data['sale_price'] >= $regular_price && $regular_price > 0 ) {
        unset( $product_data['sale_price'] );
        unset( $product_data['sale_price_forced'] );
        // ... unset other sale price fields
    }
}

Hook Reference

Sale Price Related

  • Location: class-get-products.php:2883
  • Hook: None (direct validation)
  • Filter Available: adt_get_product_data (line 4245) - can modify product data

Language Related

  • Hook: woosea_before_get_products (action)

    • Location: class-get-products.php:2095
    • Handler: WPML::set_language_before_processing() (priority 10)
  • Hook: adt_product_feed_get_products_query_args (filter)

    • Location: class-get-products.php:2200
    • Handler: WPML::set_product_query_language() (priority 10)
  • Hook: adt_after_product_feed_generation (action)

    • Location: Product_Feed.php:745
    • Handler: WPML::reset_language_after_processing() (priority 20)

Testing Checklist

Sale Price Tests

  • Product with expired sale → No sale price in feed
  • Product with future sale → No sale price in feed
  • Product with valid sale → Sale price in feed
  • Product with sale = regular → No sale price in feed
  • Product with sale > regular → No sale price in feed
  • Variable product with sale → Correct sale price

Language Tests

  • Default language feed → Products in default language
  • Non-default language feed → Products in selected language
  • Feed with no language set → Uses default language
  • Multiple feeds, different languages → Each in correct language
  • Products without translation → Handled correctly

Code Snippets

Add Custom Sale Price Validation

add_filter( 'adt_get_product_data', function( $product_data, $feed, $product ) {
    // Your custom validation
    if ( isset( $product_data['sale_price'] ) ) {
        // Custom logic here
    }
    return $product_data;
}, 10, 3 );

Add Custom Language Handling

add_action( 'woosea_before_get_products', function( $feed ) {
    // Your custom language setup
    if ( $feed->custom_language ) {
        // Switch to custom language
    }
}, 5, 1 ); // Priority 5 to run before WPML (10)

Debug Feed Generation

add_action( 'woosea_before_get_products', function( $feed ) {
    error_log( 'Feed Generation Started - ID: ' . $feed->id );
    error_log( 'Feed Language: ' . ( $feed->wpml ?? 'default' ) );
    error_log( 'Feed Channel: ' . $feed->channel );
}, 1, 1 );

Troubleshooting

Issue: Sale prices still wrong

  1. Check if discount plugin is active
  2. Verify sale dates in database
  3. Check WooCommerce sale status
  4. Review validation logs

Issue: Language not working

  1. Verify WPML is active and configured
  2. Check adt_enable_wpml_support option
  3. Verify products have translations
  4. Check language selection in feed settings
  5. Review WPML debug logs

Issue: Performance problems

  1. Check Action Scheduler status
  2. Review batch sizes
  3. Check for memory issues
  4. Review query performance

File Locations

Component File Path
Sale Price Validation woo-product-feed-pro/classes/class-get-products.php:2883-2916
WPML Language Switch woo-product-feed-elite/includes/Integrations/WPML.php:135-147
WPML Query Filter woo-product-feed-elite/includes/Integrations/WPML.php:272-291
Product Query Hook woo-product-feed-pro/classes/class-get-products.php:2200
Before Products Hook woo-product-feed-pro/classes/class-get-products.php:2095

Version History

  • v1.0 (2024): Initial implementation
    • Sale price validation added
    • WPML language switching fixed
    • Query language filtering added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment