Quote from Alex Dovlatov on November 10, 2025, 12:56
Basically it is possible to do by functions:
$woocs = new WOOCS();
$woocs->recalculate_order(515, 'EUR');
If you need snippet you can ask AI, here is an example:
add_action('wp', 'schedule_order_currency_conversion');
function schedule_order_currency_conversion() {
if (!wp_next_scheduled('convert_orders_to_base_currency')) {
// Run daily at 3 AM
wp_schedule_event(time(), 'daily', 'convert_orders_to_base_currency');
}
}
// Hook the conversion function
add_action('convert_orders_to_base_currency', 'convert_all_orders_to_base_currency');
function convert_all_orders_to_base_currency() {
if (class_exists('WOOCS')) {
$woocs = new WOOCS();
$base_currency = 'USD';
// Get all orders that are NOT in base currency
$args = array(
'limit' => -1,
'status' => array('wc-completed', 'wc-processing', 'wc-on-hold'),
'meta_query' => array(
array(
'key' => '_order_currency',
'value' => $base_currency,
'compare' => '!='
)
)
);
$orders = wc_get_orders($args);
foreach ($orders as $order) {
$order_id = $order->get_id();
$order_currency = $order->get_currency();
// Skip if already in base currency
if ($order_currency === $base_currency) {
continue;
}
// Store original values before conversion
$order->update_meta_data('_original_currency', $order_currency);
$order->update_meta_data('_original_total', $order->get_total());
$order->update_meta_data('_conversion_date', current_time('mysql'));
$order->save();
// Convert order to base currency
$woocs->recalculate_order($order_id, $base_currency);
}
}
}
// Deactivation hook to clear scheduled event
register_deactivation_hook(__FILE__, 'deactivate_currency_conversion_cron');
function deactivate_currency_conversion_cron() {
$timestamp = wp_next_scheduled('convert_orders_to_base_currency');
wp_unschedule_event($timestamp, 'convert_orders_to_base_currency');
}
Basically it is possible to do by functions:
$woocs = new WOOCS();
$woocs->recalculate_order(515, 'EUR');
If you need snippet you can ask AI, here is an example:
add_action('wp', 'schedule_order_currency_conversion');
function schedule_order_currency_conversion() {
if (!wp_next_scheduled('convert_orders_to_base_currency')) {
// Run daily at 3 AM
wp_schedule_event(time(), 'daily', 'convert_orders_to_base_currency');
}
}
// Hook the conversion function
add_action('convert_orders_to_base_currency', 'convert_all_orders_to_base_currency');
function convert_all_orders_to_base_currency() {
if (class_exists('WOOCS')) {
$woocs = new WOOCS();
$base_currency = 'USD';
// Get all orders that are NOT in base currency
$args = array(
'limit' => -1,
'status' => array('wc-completed', 'wc-processing', 'wc-on-hold'),
'meta_query' => array(
array(
'key' => '_order_currency',
'value' => $base_currency,
'compare' => '!='
)
)
);
$orders = wc_get_orders($args);
foreach ($orders as $order) {
$order_id = $order->get_id();
$order_currency = $order->get_currency();
// Skip if already in base currency
if ($order_currency === $base_currency) {
continue;
}
// Store original values before conversion
$order->update_meta_data('_original_currency', $order_currency);
$order->update_meta_data('_original_total', $order->get_total());
$order->update_meta_data('_conversion_date', current_time('mysql'));
$order->save();
// Convert order to base currency
$woocs->recalculate_order($order_id, $base_currency);
}
}
}
// Deactivation hook to clear scheduled event
register_deactivation_hook(__FILE__, 'deactivate_currency_conversion_cron');
function deactivate_currency_conversion_cron() {
$timestamp = wp_next_scheduled('convert_orders_to_base_currency');
wp_unschedule_event($timestamp, 'convert_orders_to_base_currency');
}