Ecommerce: Change "Country Taxes" text

Hey all!

This wording comes back from Stripe or Taxjar I believe and will be based on the language set in the browser.

One of the team has written this script you can add to your page (just change “XYZ Tax” to what you want)

<script>
const translations = {
  "State Taxes": "XYZ Tax",
  "City Taxes": "XYZ Tax",
  "County Taxes": "XYZ Tax",
  "Country Taxes": "XYZ Tax",
  "Discount": "<translated>",
};

// **************************************************************** //
const extraItemsNode = document.getElementsByClassName(
  "w-commerce-commercecheckoutordersummaryextraitemslist"
)[0];

const config = {
  characterData: true,
  attributes: true,
  childList: true,
  subtree: true,
};

const callback = function (mutationsList, observer) {
  for (let mutation of mutationsList) {
    if (mutation.type !== "childList") {
      continue;
    }
    for (const addedNode of mutation.addedNodes) {
      if (!addedNode.firstChild) {
        continue;
      }
      for (const translationString in translations) {
        if (~addedNode.firstChild.innerText.indexOf(translationString)) {
          addedNode.firstChild.innerText = addedNode.firstChild.innerText.replace(translationString, translations[translationString]);
        }
      }
    }
  }
};

const observer = new WebKitMutationObserver(callback);
observer.observe(extraItemsNode, config);
</script>
1 Like