daily pastebin goal
51%
SHARE
TWEET

WooCommerce - Sort attributes by name

lorro Sep 25th, 2015 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // Sorts attributes alphabetically on the Attributes page and in the select dropdown on product pages
  3.   // not tested exhaustively!
  4.   // Code goes in functions.php of your child theme
  5.  
  6.   add_filter('woocommerce_attribute_taxonomies', 'custom_attribute_sort');
  7.   function custom_attribute_sort($array) {
  8.     usort($array, 'compareName');
  9.     return $array;
  10.   }
  11.  
  12.   function compareName($attribute_1, $attribute_2) {
  13.     if ($attribute_1->attribute_name == $attribute_2->attribute_name) {
  14.       return 0;
  15.     }
  16.     return ($attribute_1->attribute_name < $attribute_2->attribute_name) ? -1 : 1;
  17.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top