If you are ready to take your WooCommerce website to the next level beyond the standard product page layout, you’re going to need to know how to create a link to put a product into the cart. This comes in hand when creating a custom landing page for a single product and you don’t have WooCommerce template functionality at hand. You might also want to redirect the user once they hit the Add Now button. Here’s a great article with a (semi) comprehensive list of custom URLs for adding products to a WooCommerce cart: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/
For our purposes, I needed to add a custom URL for our Variable Subscriptions, which the above article didn’t address.
WooCommerce Custom Add to Cart URL for Variable Subscriptions
Product ID
The first step is to locate the product ID, found in the list of products:
Once you have the product ID, start the link with the following href:
http://cinchws.com/cart/?add-to-cart=30
Variation ID
The next step is to locate the Variation ID. It’s within the product you want under the variations tab:
We will add &variation_id=idnumber
to the end of the url and now looks like this:
https://cinchws.com/cart/?add-to-cart=30&variation_id=12190
Frequency
The final piece to create the URL is to grab the frequency attribute. Open up the variation you want and find it under Subscription Length:
The final URL will add &atrribute_frequency=Duration
to the end of the URL like this:
https://cinchws.com/cart/?add-to-cart=30&variation_id=12190&attribute_frequency=Never+Expire
I hope this helps others out there who need to know how to build out a custom add-to-cart link using WooCommerce Subscriptions. Comment below if you found it useful.
5 Comments
The never+expire attribute didn’t pull the subscription product into the cart. How do you add to cart if you have multiple subscription frequencies for each variable product?
Hi Anna,
Do you have AJAX enabled for your cart? I’m not sure that’s the fix, but just wanted to check there first.
I needed to know the variation bit to update an existing link. Thanks.
Just a little bonus tip; instead of /cart/?add-to-cart… you can use /checkout/?add-to-cart… to add to cart and go directly to checkout.
Hi there,
Wondering how to add specific subscription frequencies to the url? I’ve tried ?&attribute_frequency=6+Weeks and &attribute_frequency=every+6+weeks and &attribute_frequency=every+6th+week to no avail.
Cheers!
Hi Lauren,
You’ll need to find the actual slug for that attribute… To do this you may need to do some sleuthing in the inspector when editing a product… Here’s an article that shows what I mean: https://www.lankawebsites.com/blog/woocommerce-add-product-directly-cart-using-url-link/