FOX - WooCommerce Currency Switcher Professional

woocs_sheduler_rates_updated

The woocs_sheduler_rates_updated (from v.2.4.5/1.4.5)action hook fires after the automatic currency rates update process completes. This hook is triggered by the WordPress cron job when exchange rates are refreshed from external sources.

When Does It Fire?

This hook executes at the end of the rate_auto_update() method, after:

  • New rates are fetched from the exchange rate API
  • Currency data is validated and updated
  • Changes are saved to the database
  • Optional email notification is sent to admin

 

Use Cases

1. Custom Notification Systems

Send updates to Slack, Telegram, or other messaging platforms:

add_action('woocs_sheduler_rates_updated', function($currencies) {
    $message = "💱 Currency rates updated:\n";
    foreach ($currencies as $code => $curr) {
        if ($curr['is_etalon'] == 1) continue;
        $message .= "{$code}: {$curr['rate']}\n";
    }
    
    // Send to Telegram
    wp_remote_post('https://api.telegram.org/bot' . YOUR_BOT_TOKEN . '/sendMessage', [
        'body' => [
            'chat_id' => YOUR_CHAT_ID,
            'text' => $message
        ]
    ]);
});

2. Rate Change Monitoring

Alert if rates change dramatically:

add_action('woocs_sheduler_rates_updated', function($currencies) {
    $old_rates = get_option('woocs_previous_rates', []);
    
    foreach ($currencies as $code => $curr) {
        if (isset($old_rates[$code])) {
            $change = abs(($curr['rate'] - $old_rates[$code]) / $old_rates[$code] * 100);
            
            if ($change > 5) { // More than 5% change
                error_log("⚠️ ALERT: {$code} rate changed by {$change}%");
                // Send urgent notification
            }
        }
    }
    
    // Save current rates for next comparison
    $rates_only = array_column($currencies, 'rate', 'name');
    update_option('woocs_previous_rates', $rates_only);
});

3. Sync with External Systems

Update rates in your ERP, accounting software, or other platforms:

add_action('woocs_sheduler_rates_updated', function($currencies) {
    // Sync to external API
    wp_remote_post('https://your-erp.com/api/rates', [
        'body' => json_encode($currencies),
        'headers' => ['Content-Type' => 'application/json']
    ]);
});

4. Custom Price Recalculation

Trigger additional updates for custom meta fields or related data:

add_action('woocs_sheduler_rates_updated', function($currencies) {
    // Update custom price fields
    $products = wc_get_products(['limit' => -1]);
    
    foreach ($products as $product) {
        // Your custom recalculation logic
        $custom_price = get_post_meta($product->get_id(), '_custom_currency_price', true);
        if ($custom_price) {
            // Recalculate based on new rates
            update_post_meta($product->get_id(), '_cached_converted_price', 
                $custom_price * $currencies['EUR']['rate']);
        }
    }
});

5. Logging & Analytics

Track rate history for analysis:

add_action('woocs_sheduler_rates_updated', function($currencies) {
    global $wpdb;
    
    foreach ($currencies as $code => $curr) {
        if ($curr['is_etalon'] == 1) continue;
        
        $wpdb->insert('wp_currency_rate_history', [
            'currency_code' => $code,
            'rate' => $curr['rate'],
            'updated_at' => current_time('mysql')
        ]);
    }
});

Priority & Timing

Add priority if execution order matters:

add_action('woocs_sheduler_rates_updated', 'my_function', 10, 1); // Default priority
add_action('woocs_sheduler_rates_updated', 'my_urgent_function', 5, 1); // Runs first

Notes

  • This hook only fires during automatic cron updates, not manual rate updates from admin panel
  • The $currencies array contains the complete updated data already saved to database
  • Hook runs after the optional admin email notification

This hook provides powerful integration capabilities for extending WOOCS functionality with custom business logic, monitoring, and third-party system synchronization.