WooCommerce add to cart link with variations

Hi, many times we have to make custom product loop and single custom product page with various design and at that time we need to give a button with add to cart URL or link with variation to add the product to cart and in this post we will going to see how the link can makes.

the add to cart link will look like


or the link maybe


first, you have to uncheck the checkbox of ajax add to cart option from WordPress admin panel

Ajax add to cart

Ajax add to cart

here first you need to get the domain URL which is https://www.your-domain.com/

then in get method, you have to send the product id with get variable add-to-cart like ?add-to-cart=<product id>

then have to send the attribute variation with to get veritable attribute_pa_ concatenating with attribute slug-like &attribute_pa_gravy=medium here gravy is the attribute slug and the medium is the variation name to show the variation name in cart and order

and then you need to send the variation id in get method with veriation_id get veritable to add the variation to the cart like &variation_id=574

now the full URL will be like

https://www.your-domain.com/?add-to-cart=<product id>&attribute_pa_<attribute slug>=<attribute name>&variation_id=<veriation id>

And thus you can be able to make an add to cart link in WordPress woo-commerce

Thanks for Reading.

Share The Post On -