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
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:
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:
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:
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.
Also published on Medium.