All things Shopify and commerce
I implemented a countryselector for US and SG, which seems to be working on all fronts except for updating the buyeridentity in the cart. When I select US, the buyeridentity in the Cart appears to be in SG still. As a result, when I add a US item to cart, it properly sends an optimistic update to cart with the correct cartlineitem, but the server seems to reject it, and the item disappears after a second or two in the cart aside. When I log the cart in CartMain, with 0 items in the cart, the countrycode is set to SG, but when the optimistic update is posted to the server, it briefly changes to US with totalquantity set to 1; upon rejection, it changes back to SG with totalquantity set to 0.
This is confusing, as I believe I followed the steps to update the cart buyer identity as shown here (https://shopify.dev/docs/storefronts/headless/hydrogen/markets/country-selector) and I also tried to unset the previous cart after updating the cart buyer identity (await session.unset('cartId');).
// If a cart exists, fetch its current buyer identity and update if needed if (cartId) { const currentCart = await cart.get(); const currentCountry = currentCart?.buyerIdentity?.countryCode; // console.log( // 'Current buyer identity:', // currentCart?.buyerIdentity?.countryCode, // ); // Compare with the country from the URL locale if (currentCountry !== locale.country) { // Update the cart's buyer identity with the new country code await updateCartBuyerIdentity(context, { cartId, buyerIdentity: {countryCode: locale.country}, }); // Optionally, you can clear the cartId from the session so a new cart is created: // await session.unset('cartId'); } }
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025