【发布时间】:2015-01-28 11:18:26
【问题描述】:
我正在使用shopify,
我用特定的产品编号和数量将用户发送到 shopify,这些产品编号和数量在 shopify 上填充了用户可以付款的价格,
现在我希望用户在付款成功后被重定向到我网站中的某个特定页面,
我创建了 webhook order payemnt 并给出了付款后要重定向的页面的 url,但它不起作用
请推荐
谢谢
【问题讨论】:
我正在使用shopify,
我用特定的产品编号和数量将用户发送到 shopify,这些产品编号和数量在 shopify 上填充了用户可以付款的价格,
现在我希望用户在付款成功后被重定向到我网站中的某个特定页面,
我创建了 webhook order payemnt 并给出了付款后要重定向的页面的 url,但它不起作用
请推荐
谢谢
【问题讨论】:
您可以通过访问设置>结帐并将其粘贴到其他内容和脚本的文本框中来设置重定向。
<style type="text/css">body {display:none}</style>
<script type="text/javascript">
window.location.replace("http://yahoo.com");
</script>
【讨论】:
如果您希望根据客户购买的产品将客户重定向到不同的 URL,那么下面是我为此创建的一些代码。
注意:此代码插入到结帐区域的附加脚本部分。去那里去设置>结帐>向下滚动到附加脚本。
此解决方案使用Shopify checkout object selector @Altin provided。
请记住,此解决方案仅适用于我的 Shopify 体验,因为客户一次只能购买 1 件产品。如果您的客户可以将多件商品添加到他们的购物车中,那么应该使用 for 循环,可能是在 for in 循环周围。
<script>
const idUrlList = {
// Replace the content below here with your own
"product1": {
"url": "https://www.URL-HERE.com",
"product_id": 1234567898765,
},
"product2": {
"url": "https://www.URL-HERE.com",
"product_id": 1234567898765,
},
"product3": {
"url": "https://www.URL-HERE.com",
"product_id": 1234567898765,
},
"product4": {
"url": "https://www.URL-HERE.com",
"product_id": 1234567898765,
},
// Replace the content above here with your own
};
// Do NOT change anything below this line
const productPurchasedId = Shopify.checkout.line_items[0].product_id;
for (const product in idUrlList) {
if (idUrlList[product].product_id === productPurchasedId) {
window.location.replace(`${idUrlList[product].url}`);
}
else {
console.log(`Found no matches in dictionary.
The dictionary ID is ${idUrlList[product].product_id}
The product ID is ${productPurchasedId}`);
};
};
</script>
要使这项工作适合您,请进行以下替换:
// Replace the content above here with your own 的行。此代码的其余部分将自动处理查找产品 ID 并处理其正确重定向。
以下是我构建此解决方案的一些参考资料:
我还发现您可以使用虚假网关测试您的网页。 Shopify documentation available here.
【讨论】: