php – Woocommerce + Timber: Get variation id based on attribute name-ThrowExceptions

Exception or error:

I’m trying to programmatically create buttons that will add products to the cart based on variations set by attributes.

My two variations are “digital” and “hard” copies of files. Not sure how to retrieve it properly based on the attribute terms of “product-type” I’ve created in my instance. Here’s what I have to do the buttons, but to no avail it’s not working of course.

{% set product = post.ID %}
  <a href="{{site.url}}/checkout/?add-to-cart={{product.variation_id.ID}}" class="button--primary button--sm">Digital Copy</a>
  <a href="{{site.url}}/checkout/?add-to-cart={{product}}" class="button--outline button--sm">Hard Copy</a>

Any help would be appreciated!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *