Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add currency code to cart and checkout block totals when mccy is enabled #8636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Make sure an explicit currency code is present in the cart and checkout blocks when multi-currency is enabled
21 changes: 20 additions & 1 deletion client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
/**
* Internal dependencies
*/
import { getUPEConfig } from 'utils/checkout';
import { getUPEConfig, getConfig } from 'utils/checkout';
import { isLinkEnabled } from '../utils/upe';
import WCPayAPI from '../api';
import { SavedTokenHandler } from './saved-token-handler';
Expand Down Expand Up @@ -158,3 +158,22 @@ window.addEventListener( 'load', () => {
enqueueFraudScripts( getUPEConfig( 'fraudServices' ) );
addCheckoutTracking();
} );

// If multi-currency is enabled, add currency code to total amount in cart and checkout blocks.
if ( getConfig( 'isMultiCurrencyEnabled' ) ) {
const { registerCheckoutFilters } = window.wc.blocksCheckout;

const modifyTotalsPrice = ( defaultValue, extensions, args ) => {
const { cart } = args;

if ( cart?.cartTotals?.currency_code ) {
return `<price/> ${ cart.cartTotals.currency_code }`;
}

return defaultValue;
};

registerCheckoutFilters( 'woocommerce-payments', {
totalValue: modifyTotalsPrice,
} );
}
15 changes: 15 additions & 0 deletions includes/multi-currency/MultiCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public function init_hooks() {
add_action( 'woocommerce_created_customer', [ $this, 'set_new_customer_currency_meta' ] );
}

add_filter( 'wcpay_payment_fields_js_config', [ $this, 'add_props_to_wcpay_js_config' ] );

$this->currency_switcher_block->init_hooks();
}

Expand Down Expand Up @@ -388,6 +390,19 @@ public function enqueue_admin_scripts() {
WC_Payments_Utils::enqueue_style( 'WCPAY_MULTI_CURRENCY_SETTINGS' );
}

/**
* Add multi-currency specific props to the WCPay JS config.
*
* @param array $config The JS config that will be loaded on the frontend.
*
* @return array The updated JS config.
*/
public function add_props_to_wcpay_js_config( $config ) {
$config['isMultiCurrencyEnabled'] = true;

return $config;
}

/**
* Wipes the cached currency data option, forcing to re-fetch the data from WPCOM.
*
Expand Down
Loading