I'm currently in the process of coding some different add to cart buttons for my variable products. I apologise if some of this isn't very coherent as I've been struggling over this for days. I'm not amazing at PHP so please try and explain any answers at a dumb level so I can actually understand them. I only have a very, very basic understanding of what I'm doing.
This is my current situation: buttons
I have a product and 3 product variants matching the titles in the boxes. I'm following an article I found and using an tag on the button to add the product to cart. This is the current code for it:
<div class="s-outr">
<div class="s-inr">
<div class="s-mrgns">
<img class="s-stndrd" src="https://test.com/wp-content/uploads/2018/10/standard.png" alt="Standard License">
<div class="s-hdr"><h3>STANDARD</h3></div>
<div class="s-cntnt"><p>Stream / Sell 1000 Copies<br>MP3 + 24bit .Wav<br> <br> </p></div>
<div class="s-price"><h3>$20</h3></div>
<a href="http://test.com/cart/?add-to-cart=<?php the_ID();?>&variation_id=<?php **NEED HELP HERE** ?>&attribute_pa_license=Standard"><button onclick="standard_license()"class="s-btn">SELECT</button>
</div>
</div>
</div>
This code is in content-single-product.php in my theme files.
So far, works, its just getting the correct variant ID for the product. All variants on the products will be in the same order, Standard, Unlimited, Exclusive, so what I'm imagining is a possible solution is to get all 3 variant IDs in some sort of array, then just select the first, second and 3rd ones for each of the tags. I'm just unsure of how to actually do this. Please let me know if you need any more information.
Most of the answers I've found utilise a foreach loop which has kind of stumped me as it seems there's no other way to do it other than that, and from what I can tell I can't use one because each of the buttons needs to have different information around them. Could be wrong.
Thanks for any help,
Cheers.