▼
Streaming live at 10am (PST)

New BUG in eCommerce- Translation of Discount

Hi i have found what i think is a new BUG. I added the new discount function for one of me clients (new port from Shopify to Webflow)

We did have problem with the translation of Country Tax simce before and now i have the same problem with the translation of the wording Discount. Have i missed something??

OrderSum

@WebDev_Brandon @johnramos

Hi @JanneWassberg

The option to change the ‘country tax’ text is currently not available natively within Webflow.

We do have a bit of custom code that can be added to the project to change the “Country Taxes” text. The code is as follows:

`const translations = {
“State Taxes”: “Doofenshmirtz Tax”,
“City Taxes”: “Doofenshmirtz Tax”,
“County Taxes”: “Doofenshmirtz Tax”,
“Country Taxes”: “Doofenshmirtz Tax”,
};

// **************************************************************** //
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 taxType in translations) {
if (~addedNode.firstChild.innerText.indexOf(taxType)) {
addedNode.firstChild.innerText = translations[taxType];
}
}
}
}
};
const observer = new WebKitMutationObserver(callback);
observer.observe(extraItemsNode, config);
`
**** Make sure you place this in a opening and closing script tags.

You can replace the text “Doofenshmirtz Tax” with what you would like to be displayed instead of “Country Taxes.”

You would also do this with the Discount one too.

Custom code is available on Webflow sites that have site plans (hosting) or projects in a paid account plan.

Please refer to the following articles for how to include custom code on Webflow sites:

Please let me know if you have any other questions,

~ Happy Designing ~
Brandon

1 Like

Hi @WebDev_Brandon,

I’ve tried to add a string for “Discount” translation into your code but it didn’t work. Maybe the code is missing some strings to apply translation for “Discount”?

@Natalia1990

The Discount element is separate from this translation. This is designed to work within the taxes area. Discounts fall under an entirely different module. Not sure if we have a translation code snippet for discounts. I will ask our team and get back to this thread if/when I do.

Brandon

@Natalia1990

Here is an updated code 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);

Don’t see much difference than the line for “Discounts”

Brandon

1 Like