Woocommerce product categories order [closed]

Woocommerce stores ‘order’ metakeys in the table wp_woocommerce_termmeta. The mechanism it uses is the same as menu_order for posts.

Something like this should work:

$terms = get_terms('product_cat');

//sort $terms somehow

$i = -1;

foreach ($terms as $term) {
  $i++;
  update_woocommerce_term_meta( $term->id, 'order', $i);
}

The same procedure can be used to sort other Woocommerce taxonomies such as product_tag and Product Attributes. For a Product Attribute named Size, the taxonomy would be pa_size, and you should replace ‘order’ by order_pa_size

Leave a Comment