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' );
TIV.NET INC., based in Toronto, Canada, develops and supports the following WooCommerce extensions:
↑ Back to top| TIV Admin Tools | A set of utilities for WooCommerce shop owners, administrators, and developers to secure, tune, and debug their store. |
| TIV Globus | Makes WooCommerce multilingual – translate product descriptions, categories, attributes, and tags. |
| TIV Multi-currency | Lets customers pay in the currency of their choice. |
| TIV Paywall | Enables the monetization of various types of content, including videos, documents, etc., by allowing the sale of access to it. |
| TIV Sales Assistant | Manage store-wide sales from one place – schedule discounts by category, tag, and country instead of editing products one by one. |