Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce add to cart URL

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.

like image 683
Andrew Turner Avatar asked Feb 02 '14 13:02

Andrew Turner


People also ask

How do I create an Add to cart URL?

To create a custom Add to Cart URL for that product, you will need to add ? add-to-cart=123 replacing 123 with the ID of your product. The result will be something like https://www.yourwebsite.com/?add-to-cart=123 . Whoever clicks on this link, will add the product 123 to their cart.

How do I change the add to cart URL in WooCommerce?

Similar to the previous term we mentioned, you need to navigate to WooCommerce > Settings > Products > General to redirect to any page. Then, enable the AJAX “Add to Cart” button and disable “Redirect to cart page after successful addition” at the same time.

How do I find my WooCommerce cart URL?

Cart URLs are easily created from the WooCommerce Settings page. Simply enable Cart URLs, add a new Cart URL with the products you've previously determined. Save and share the cart link. The option to give each Cart URL a unique name and pretty permalink, (visible to the customer) is available.


1 Answers

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.

like image 101
Michael Visser Avatar answered Oct 04 '22 18:10

Michael Visser