Skip to content

Instantly share code, notes, and snippets.

@artikus11
Created January 3, 2022 18:22
Show Gist options
  • Save artikus11/1d2b2459474154fd27d4e01cb4391e7a to your computer and use it in GitHub Desktop.
Save artikus11/1d2b2459474154fd27d4e01cb4391e7a to your computer and use it in GitHub Desktop.
/**
* Сортировка атрибутов в админке по алфавиту
*
* @param $attr
*
* @return array
*
* @testedwith WooCommerce 6.0
* @author Artem Abramovich
*/
function art_woocommerce_sorting_attributes_list( $attr ) {
return wp_list_sort( $attr, 'attribute_label', 'ASC' );
}
add_filter( 'woocommerce_attribute_taxonomies', 'art_woocommerce_sorting_attributes_list' );
@mesulullogic
Copy link

How do i add this to my wordpress and arrange the parent attributes after getting this code

@armorally
Copy link

I put this in my child theme functions.php and there was no change to the Products > Attribute page.

@artikus11
Copy link
Author

artikus11 commented Dec 6, 2023

I put this in my child theme functions.php and there was no change to the Products > Attribute page.

It should work. I checked on several sites, the snippet works. But sometimes it may not work, I don't know why, I'll have time to figure it out

@MagnusOxlund
Copy link

How would you get the attribute slug from a WP_Taxonomy instance?

Why does WooCommerce use WP_Taxonomy instances anyway? I thought they had their own WC_Product_Attribute class.

@artikus11
Copy link
Author

artikus11 commented Oct 22, 2024

How would you get the attribute slug from a WP_Taxonomy instance?

Why does WooCommerce use WP_Taxonomy instances anyway? I thought they had their own WC_Product_Attribute class.

No way. This is not required. I'm just sorting through what's already there. The woocommerce_attribute_taxonomies filter is triggered after all attributes are received. You don't need to receive anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment