Skip to content

Instantly share code, notes, and snippets.

@vvkh
Last active January 19, 2024 17:00
Show Gist options
  • Save vvkh/d8ca7657fa85ffd120c3fc5329d8818c to your computer and use it in GitHub Desktop.
Save vvkh/d8ca7657fa85ffd120c3fc5329d8818c to your computer and use it in GitHub Desktop.
Translate "buy now" button in Shopify
<script>
// Add this snippet to the page with the "buy now" button.
// If you need dynamic translation to different languages,
// add products.product.buy_now translation to the locales file.
// Otherwise replace {{'products.product.buy_now' | t }} with desired translation.
const intervalTime = 100;
function updateButton() {
const paymentButton = document.querySelector('[data-testid="Checkout-button"]');
if (paymentButton !== null) {
console.log(paymentButton);
paymentButton.textContent = "{{'products.product.buy_now' | t }}";
clearInterval(interval);
}
}
const interval = setInterval(updateButton, intervalTime);
</script>
@1000p
Copy link

1000p commented Mar 11, 2023

This is a lifesaver, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment