Skip to content

Instantly share code, notes, and snippets.

@Inzman
Created February 10, 2020 11:31
Show Gist options
  • Save Inzman/525ad6512dbf64c6aa7bcfcc2915f041 to your computer and use it in GitHub Desktop.
Save Inzman/525ad6512dbf64c6aa7bcfcc2915f041 to your computer and use it in GitHub Desktop.
Sort woocommerce order items alphabetically
/*
* Filters the $order->get_items() method results to order all line items by
* product name
*/
add_filter( 'woocommerce_order_get_items', function( $items, $order ) {
uasort( $items,
function( $a, $b ) {
return strnatcmp( $a['name'], $b['name'] );
}
);
return $items;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment