Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sekmet/0f5ac6635803ec05043383d66635de28 to your computer and use it in GitHub Desktop.
Save sekmet/0f5ac6635803ec05043383d66635de28 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment