Skip to content
Advertisement

Get WooCommerce specific product attribute terms sorted by “menu order”

I want to sort get_the_terms by menu_order of the curent product and till now i have this code:

JavaScript

Advertisement

Answer

There is 2 ways to get the product attribute term names sorted by menu order (for a defined product):

1). Using wp_get_post_terms() function (WordPress way)

The WordPress function get_the_terms() doesn’t allow to alter the WP_Term_Query

So instead you will use similar wp_get_post_terms() that allows WP_Term_Query tuning.

JavaScript

2). Simply using WC_Product method get_attribute() (WooCommerce way)

JavaScript

Both ways work.

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