Skip to content
Advertisement

Get the selected variation attributes from orders in Woocommerce 3

In Woocommerce, I have a report in the admin area that tallies up products sold.There are only 5 products sold on the site but there are 1 or 2 variations on some. The report works great but ignores the variations.
I need to retrieve the attribute value from items ordered to display the data accurately.
How do I do this?

get_variation_description() is not working the way I’m applying it.

My code:

JavaScript

Advertisement

Answer

2020 Update – Handling “Custom Product Attributes” (revamped code)

The WC_Product method get_variation_description() is outdated and deprecated. It’s replaced by get_description() method. So you need to get the WC_Product object first.

To get the selected variation attributes, you will use get_variation_attributes( ) method.

JavaScript

Tested and works for a product variation as all other product types…

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