php Woocommerce 添加到购物车 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21511395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Woocommerce add to cart URL
提问by Andrew Turner
I am trying to work out whether it might be possible to put a straightforward HTML URL link on a button in order to add a product to a woocommerce cart. I am using a wordpress theme to show digital downloadable products but the theme itself has no cart and checkout facility so I am trying to use woocommerce for this.
我正在尝试确定是否可以在按钮上放置一个简单的 HTML URL 链接,以便将产品添加到 woocommerce 购物车。我正在使用 wordpress 主题来显示可下载的数字产品,但主题本身没有购物车和结账设施,所以我试图为此使用 woocommerce。
I have a button for each of my products which can contain a URL to link directly to the downloadable file but when clicked I want it instead to add the product to the woocommerce cart.
我的每个产品都有一个按钮,其中可以包含一个 URL 以直接链接到可下载文件,但单击时我希望将产品添加到 woocommerce 购物车。
There appears to be a way to do this using a shortcode but the theme is stripping out the square brackets to I need a full URL instead.
似乎有一种方法可以使用短代码来做到这一点,但主题是去掉方括号,我需要一个完整的 URL。
回答by Michael Visser
You cannot link directly to the downloadable file as it is stored in a protected directory, if you simply want to have a URL that adds a specific Product to your Cart and open the Cart/Checkout page then this will help.
您无法直接链接到可下载文件,因为它存储在受保护的目录中,如果您只想拥有一个将特定产品添加到您的购物车的 URL 并打开购物车/结帐页面,那么这将有所帮助。
http://yourproducturl.com/checkout/?add-to-cart=%ID%
http://yourproducturl.com/checkout/?add-to-cart=%ID%
http://yourproducturl.com/cart/?add-to-cart=%ID%
http://yourproducturl.com/cart/?add-to-cart=%ID%
Replace %ID%with the Post ID of the specific Product so that when the link is clicked, the visitor will be redirected to the Cart/Checkoutpage with the above Product added to their Cart.
替换%ID%为特定产品的帖子 ID,这样当点击链接时,访问者将被重定向到购物车/结帐页面,并将上述产品添加到他们的购物车中。

