Skip to content
Advertisement

How to get current selected variable product specific data in WooCommerce

I want to access the selected product variation Weight value in php. I tried below code its getting last value of attribute, not selected.

JavaScript

Advertisement

Answer

The selected variation properties can only be accessed via Javascript as it’s a client side live event… Here below is an example, that will display the selected variation custom attribute “attribute_weight” term slug for the variable product, below add to cart button:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

Related: Get currently selected variation id from Woocommerce variable product

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement