If you’ve ever needed an add to cart button or link and couldn’t figure out an easy way to do it this trick is for you. This trick works for WooCommerce, so if you are using something else, this ain’t for you.
WordPress is full of useful tricks, but very rarely are they obvious. This is one of those non-obvious tricks.
Find the product ID
Firstly, we are going to need to find the ID of the product you want to add to cart. To do this, simply go to products in the WordPress admin area. Hover over the product and you should see the ID.
Create your link with this query string
Now you will need to create your link or button. This should work on any page builder, blocks editor or whatever you are using (as long as it gives you the ability to add a button or text link). The key part is to add this query string to your link. ?add-to-cart=5991 (with 5991 being the product ID in the case above). So, it should look something like https://yoursite.com/?add-to-cart=5991
Save your work and test it out. You should now be able to easily add that product to cart just by clicking the link.