WooCommerce Multi-currency: Developers FAQ

Multi-currency for WooCommerce by TIV.NET

https://woocommerce.com/products/multi-currency/

How do I get the currently selected currency?

↑ Back to top
get_woocommerce_currency()

How to set the currency when I create an order programmatically?

↑ Back to top

You 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' );

Related Products

Let customers subscribe to your products or services and pay on a weekly, monthly or annual basis.

Power your membership association, online magazine, elearning sites, and more with access control to content/products and member discounts.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.