【问题标题】:Redirect user to a page after payment in shopify在shopify中付款后将用户重定向到页面
【发布时间】:2015-01-28 11:18:26
【问题描述】:

我正在使用shopify,

我用特定的产品编号和数量将用户发送到 shopify,这些产品编号和数量在 shopify 上填充了用户可以付款的价格,

现在我希望用户在付款成功后被重定向到我网站中的某个特定页面,

我创建了 webhook order payemnt 并给出了付款后要重定向的页面的 url,但它不起作用

请推荐

谢谢

【问题讨论】:

    标签: asp.net shopify webhooks


    【解决方案1】:

    您可以通过访问设置>结帐并将其粘贴到其他内容和脚本的文本框中来设置重定向。

    <style type="text/css">body {display:none}</style>
    <script type="text/javascript">
    window.location.replace("http://yahoo.com");
    </script>
    

    【讨论】:

    • 是否有任何参数可用于将这些 URL 传递给 Shopify,然后 Shopify 将根据成功和失败做出决定并相应地重定向。
    【解决方案2】:

    如果您希望根据客户购买的产品将客户重定向到不同的 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>
    

    要使这项工作适合您,请进行以下替换:

    1. 将“product1”替换为您会记住的产品名称或重定向。例如,在我的一篇文章中,我写了“20_off_2020”。
    2. https://www.URL-HERE.com 替换为您希望人们访问的链接。例如,https://theamsalems.com/
    3. 将 1234567898765 替换为您要检查的唯一产品 ID。这可以在 Shopify 中找到。转到产品,点击一个产品,然后抓取 URL 末尾的数字字符串。
    4. 根据您拥有的产品数量添加/删除其他产品。例如,如果您只有两个产品,请删除“product3”中的代码,一直到显示// Replace the content above here with your own 的行。

    此代码的其余部分将自动处理查找产品 ID 并处理其正确重定向。

    以下是我构建此解决方案的一些参考资料:

    1. Shopify checkout object, line_items array
    2. Line items product ID

    我还发现您可以使用虚假网关测试您的网页。 Shopify documentation available here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-13
      • 2014-07-15
      • 2012-06-26
      • 2018-11-29
      • 2012-12-31
      • 1970-01-01
      • 2013-07-13
      • 2021-07-04
      相关资源
      最近更新 更多