Multi-currency for WooCommerce by TIV.NET
https://woocommerce.com/products/multi-currency/
How do I get the currently selected currency?
↑ Back to topget_woocommerce_currency()
How to set the currency when I create an order programmatically?
↑ Back to topYou need to override the active currency temporarily:
function ___return_currency_USD() {
return 'USD';
}
// Temporarily set active currency to "USD".
\add_filter( 'woocommerce_multicurrency_override_currency', '___return_currency_USD' );
// Create order programmatically.
$logger = \wc_get_logger();
$product_id = 10;
try {
$order = \wc_create_order();
$order->add_product( \wc_get_product( $product_id ), 1 );
$order->calculate_totals();
$order->save();
$logger->log( \WC_Log_Levels::INFO, 'Order total = ' . $order->get_total() . ' ' . $order->get_currency() );
} catch ( \Exception $exception ) {
$logger->log( \WC_Log_Levels::ERROR, "Cannot add product ID ${product_id} to the order." );
}
// Stop overriding currency.
\remove_filter( 'woocommerce_multicurrency_override_currency', '___return_currency_USD' );