I want to sort get_the_terms by menu_order of the curent product and till now i have this code:
$colors='';
$terms = get_the_terms( get_the_ID(), 'pa_colors' );
foreach ( $terms as $term ) {
$colors='<pre>'.$term->name.'</pre>';
}
echo $colors;
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 theWP_Term_Query
…So instead you will use similar
wp_get_post_terms()
that allowsWP_Term_Query
tuning.2). Simply using
WC_Product
methodget_attribute()
(WooCommerce way)Both ways work.