How can I fetch the order currency in WooCommerce with HPOS compatibility?
How can I fetch the order currency in WooCommerce with HPOS compatibility?
I'm working on a WooCommerce project and facing an issue with fetching the correct currency for orders when High Performance Order Storage (HPOS) is enabled. My goal is to retrieve the currency specifically from the WooCommerce edit order page. Currently, my code returns the default currency set in WooCommerce settings, not the actual currency of the individual order.
Here's the code snippet I'm using:
private static function getAdminOrderCurrency($order): string {
if (OrderUtil::custom_orders_table_usage_is_enabled()) {
// HPOS usage is enabled.
$order_id = get_the_ID();
$order = wc_get_order($order_id);
return $order->get_currency();
} else {
// Traditional CPT-based orders are in use.
global $post;
$order_id = $post->ID;
$order = wc_get_order($order_id);
return $order->get_currency();
}
}
Despite this implementation, the function returns the default WooCommerce currency instead of the actual currency of the order. Could anyone suggest what might be going wrong or how to ensure compatibility with HPOS to fetch the correct currency from the WooCommerce order? Any insights or suggestions would be greatly appreciated!
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand