How to pass/get data to/from the WooCommerce data-product_variations object?


What is the best way to pass/get data to/from the data-product_variations attr form in Product Single pages. I am working on some interactions with the product gallery images and the product variations, all of these while using WooCommerce.

Basically, I need to be able to trigger some stuff on the woocommerce_variation_has_changed event.

I have been able to pass and get my data attributes while hooking to single_product_large_thumbnail_size and woocommerce_single_product_image_thumbnail_html.

I have not been able to pass/get that data during the woocommerce_variation_has_changed event. What I have understood (?) is that the woocommerce_variation_has_changed trigger gets its data from the data-product_variations object to insert the product variation related image markup.

Summing it up, how would I go to add data attr’s to the data-product_variations object? And what would be the best way to get that data during the woocommerce_variation_has_changed event?

This is how the object inside the data-product_variations looks like.
Basically I need to be able to pass a data-attr to the featured image tag when woocommerce_variation_has_changed kicks in.

    "variation_id": 373,
    "variation_is_visible": true,
    "variation_is_active": true,
    "is_purchasable": true,
    "display_price": 100,
    "display_regular_price": 100,
    "attributes": {
        "attribute_pa_chain-length": "80cm"
    "image_src": "",
    "image_link": "",
    "image_title": "",
    "image_alt": "",
    "image_caption": "",
    "image_srcset": "",
    "image_sizes": "",
    "price_html": "<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>100.00</span></span>",
    "availability_html": "",
    "sku": "",
    "weight": " kg",
    "dimensions": "",
    "min_qty": 1,
    "max_qty": null,
    "backorders_allowed": false,
    "is_in_stock": true,
    "is_downloadable": false,
    "is_virtual": false,
    "is_sold_individually": "no",
    "variation_description": ""
, , , ameraz 7 years 2016-12-06T10:31:56-05:00 0 Answers 101 views 0

Leave an answer