[英]How to make Shopify Buy Buttons redirect to checkout in a specific language?
I have an English and a Dutch version of my external website.我的外部网站有英文版和荷兰文版。 On this website, I embed multiple buy buttons for products I want to sell.在这个网站上,我为我想要销售的产品嵌入了多个购买按钮。 All these products don't use a cart;所有这些产品都不使用购物车; they directly go to the checkout page.他们直接 go 到结帐页面。 Since I want a multi-language checkout (because my external website is also multi-language), I bought a Weglot subscription to translate the checkout page.由于我想要多语言结帐(因为我的外部网站也是多语言的),所以我购买了 Weglot 订阅来翻译结帐页面。 The only thing is, I can view the English version of the store (via this URL https://en.shop.hofleveranciervanrubens.be/ ), but I can't seem to use this URL on my buy buttons to redirect customers to the correct English version of the checkout (Dutch is the 'main' Shopify language) The only thing is, I can view the English version of the store (via this URL https://en.shop.hofleveranciervanrubens.be/ ), but I can't seem to use this URL on my buy buttons to redirect customers to结帐的正确英文版本(荷兰语是“主要”Shopify 语言)
I saw a lot of people doing this tutorial to localize their buy button, but the afterInit() event won't trigger (I think because I have direct checkout, not a cart) https://www.felixparadis.com/posts/localization-of-shopifys-buy-buttons/我看到很多人在做这个教程来本地化他们的购买按钮,但是 afterInit() 事件不会触发(我想是因为我有直接结帐,而不是购物车) https://www.felixparadis.com/posts/ shopifys-buy-buttons的本地化/
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('product', {
id: '6750224449710',
node: document.getElementById('product-component-1627130549176'),
moneyFormat: '%24%7B%7Bamount%7D%7D',
options: {
"product": {
// Skipping lots of code for brevity ...
},
"productSet": {
// Skipping lots of code for brevity ...
},
"modalProduct": {
// Skipping lots of code for brevity ...
},
"option": {},
"cart": {
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * 👇THIS IS WHERE MAGIC HAPPENS👇
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"events": {
afterInit: (cart) => {
cart.onCheckout = () => {
const checkoutUrl = cart.model.webUrl + '&locale=en';
cart.checkout.open(checkoutUrl);
};
},
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * 👆THIS IS WHERE MAGIC HAPPENS👆
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"styles": {
// Skipping lots of code for brevity ...
},
"text": {
// Skipping lots of code for brevity ...
},
"popup": false
},
"toggle": {
// Skipping lots of code for brevity ...
}
}
})
})
This is the external URL of my website: https://www.hofleveranciervanrubens.be/这是我网站的外部 URL: https://www.hofleveranciervanrubens.be/
My question summarised: How do I let Shopify know in which language they should display their checkout via their buybutton.js?我的问题总结了:我如何让 Shopify 知道他们应该通过他们的 buybutton.js 以哪种语言显示他们的结帐?
I think you're right in saying that the code you pasted doesn't work because you're not using the cart functionality.我认为您说您粘贴的代码不起作用是正确的,因为您没有使用购物车功能。
In fact, in the documentation here http://shopify.github.io/buy-button-js/ you can see that the Cart component has events, whereas the Checkout seems to not have them.事实上,在http://shopify.github.io/buy-button-js/的文档中,您可以看到 Cart 组件有事件,而 Checkout 似乎没有。
I think you can try playing a bit with the events and the debugger to see if you manage to break on the right event and change the URL from there.我认为您可以尝试使用事件和调试器来查看您是否设法中断正确的事件并从那里更改 URL。
Anyway there is always a way to make it work.无论如何,总有办法让它发挥作用。 Actually two.其实两个。 You can modify all the checkout links adding your "&locale=en" after shopify buy has been initialized or you can change the link on the go, while is clicking.您可以在 shopify 购买初始化后修改所有结帐链接添加“&locale=en”,或者您可以在点击时更改 go 上的链接。 The second way is a bit more convoluted but it assures that is alway applied, even in case of lazy loading or things like that.第二种方式有点复杂,但它确保始终应用,即使在延迟加载或类似的情况下也是如此。
Solution 2 would look like something like this: (I'm taking inspiration from this answer https://stackoverflow.com/a/33616981/343794 ).解决方案 2 看起来像这样:(我从这个答案https://stackoverflow.com/a/33616981/343794中获得灵感)。
function interceptClickEvent(e) {
var href;
var target = e.target || e.srcElement;
if (target.tagName === 'A') {
href = target.getAttribute('href');
if (href.indexOf("checkout")>=0) { //filtering only checkout links
window.open(href+"&locale=en",'_blank');
e.preventDefault();
}
}
}
//listen for link click events at the document level
document.addEventListener('click', interceptClickEvent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.