lorro

WooCommerce - Attribute order alphabetical by name

Jan 21st, 2021 (edited)
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2. // WooCommerce - Attribute order alphabetical by name
  3. // default order is alphabetical by slug  
  4. add_filter( 'woocommerce_attribute_taxonomies', 'custom_attribute_sorting' );
  5. function custom_attribute_sorting( $attribute_taxonomies ) {
  6.   usort( $attribute_taxonomies, 'sort_by_attribute_label');
  7.   return $attribute_taxonomies;
  8. }
  9. function sort_by_attribute_label( $a, $b ) {
  10.   if( $a->attribute_label == $b->attribute_label ){ return 0; }
  11.   return ($a->attribute_label < $b->attribute_label) ? -1 : 1;
  12. }
Add Comment
Please, Sign In to add comment