Php – Woocommerce add to cart URL

PHPwoocommerceWordpress

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.

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.

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.

Best Answer

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.

http://yourproducturl.com/checkout/?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/Checkout page with the above Product added to their Cart.

Related Topic