Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Shopify添加到购物车按钮重定向到和追加销售页面_Javascript_Jquery_Redirect_Shopify - Fatal编程技术网

Javascript Shopify添加到购物车按钮重定向到和追加销售页面

Javascript Shopify添加到购物车按钮重定向到和追加销售页面,javascript,jquery,redirect,shopify,Javascript,Jquery,Redirect,Shopify,我有购买按钮代码,它工作得很好。我需要做的是点击按钮后,页面重定向到另一个页面,一个追加销售页面。销售页面在shopify之外,所以我使用shopify提供的购买按钮代码。问题是,我需要嵌入按钮的页面在单击按钮后重定向到另一个页面,以便在重定向之前将产品添加到购物车 这是购买按钮代码 <div id='product-component-NUMBER'></div> <script type="text/javascript"> /*<![CDATA[*

我有购买按钮代码,它工作得很好。我需要做的是点击按钮后,页面重定向到另一个页面,一个追加销售页面。销售页面在shopify之外,所以我使用shopify提供的购买按钮代码。问题是,我需要嵌入按钮的页面在单击按钮后重定向到另一个页面,以便在重定向之前将产品添加到购物车

这是购买按钮代码

<div id='product-component-NUMBER'></div>
<script type="text/javascript">
/*<![CDATA[*/

(function () {
  var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/buy-button-storefront.min.js';
  if (window.ShopifyBuy) {
    if (window.ShopifyBuy.UI) {
      ShopifyBuyInit();
    } else {
      loadScript();
    }
  } else {
    loadScript();
  }

  function loadScript() {
    var script = document.createElement('script');
    script.async = true;
    script.src = scriptURL;
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
    script.onload = ShopifyBuyInit;
  }

  function ShopifyBuyInit() {
    var client = ShopifyBuy.buildClient({
      domain: 'THESHOP.myshopify.com',
      apiKey: 'APIKEY',
      appId: '6',
    });

    ShopifyBuy.UI.onReady(client).then(function (ui) {
      ui.createComponent('product', {
        id: [8888888888],
        node: document.getElementById('product-component-NUMBER'),
        moneyFormat: '%24%7B%7Bamount%7D%7D',
        options: {
  "product": {
    "variantId": "all",
    "width": "380px",
    "contents": {
      "imgWithCarousel": false,
      "variantTitle": false,
      "description": false,
      "buttonWithQuantity": true,
      "button": false,
      "quantity": false
    },
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "100%",
          "margin-left": "0",
          "margin-bottom": "50px"
        }
      },
      "button": {
        "background-color": "#e43030",
        "font-family": "Lato, sans-serif",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        "padding-left": "50px",
        "padding-right": "50px",
        ":hover": {
          "background-color": "#cd2b2b"
        },
        ":focus": {
          "background-color": "#cd2b2b"
        },
        "font-weight": "bold"
      },
      "quantityInput": {
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px"
      },
      "compareAt": {
        "font-size": "12px"
      }
    },
    "googleFonts": [
      "Lato"
    ]
  },
  "cart": {
    "contents": {
      "button": true
    },
    "styles": {
      "button": {
        "background-color": "#e43030",
        "font-family": "Lato, sans-serif",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        ":hover": {
          "background-color": "#cd2b2b"
        },
        ":focus": {
          "background-color": "#cd2b2b"
        },
        "font-weight": "bold"
      },
      "footer": {
        "background-color": "#ffffff"
      }
    },
    "googleFonts": [
      "Lato"
    ]
  },
  "modalProduct": {
    "contents": {
      "img": false,
      "imgWithCarousel": true,
      "variantTitle": false,
      "buttonWithQuantity": true,
      "button": false,
      "quantity": false
    },
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "100%",
          "margin-left": "0px",
          "margin-bottom": "0px"
        }
      },
      "button": {
        "background-color": "#e43030",
        "font-family": "Lato, sans-serif",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        "padding-left": "50px",
        "padding-right": "50px",
        ":hover": {
          "background-color": "#cd2b2b"
        },
        ":focus": {
          "background-color": "#cd2b2b"
        },
        "font-weight": "bold"
      },
      "quantityInput": {
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px"
      }
    },
    "googleFonts": [
      "Lato"
    ]
  },
  "toggle": {
    "styles": {
      "toggle": {
        "font-family": "Lato, sans-serif",
        "background-color": "#e43030",
        ":hover": {
          "background-color": "#cd2b2b"
        },
        ":focus": {
          "background-color": "#cd2b2b"
        },
        "font-weight": "bold"
      },
      "count": {
        "font-size": "18px"
      }
    },
    "googleFonts": [
      "Lato"
    ]
  },
  "productSet": {
    "styles": {
      "products": {
        "@media (min-width: 601px)": {
          "margin-left": "-20px"
        }
      }
    }
  }
}
      });
    });
  }
})();
/*]]>*/
</script>

/**/

当Shopify在所有主题中加载jQuery时,您可以使用它。然后只需使用
preventDefault()
,然后将购物者发送到您想要的任何地方。
单击事件将如下所示:

$("#idOfMyButton").click(function(event){
  event.preventDefault();
  window.location.href = "http://sendtowherever.com";            
});