For a WC plugin I'm working on, I need to find the attribute that defines the variations of a product.
So, suppose we have a variable product that has attributes likes Color, Size, Material, but only "sizes" defines the variations. Then, I'd like an algorithm (I doubt there is a single WooCommerce method) to get the Size attribute (or its ID/slug).
Any help will be highly appreciated.
You can use
get_variation_attributes()method from a variable product like:Note that there are taxonomy attributes (for variations) and also custom attributes (for variations) not registered globally.
$attributeis the taxonomy and$valuesan array of term slugs.$attributeis the main attribute name and$valuesan array of values names.