Created
February 10, 2020 11:31
-
-
Save Inzman/525ad6512dbf64c6aa7bcfcc2915f041 to your computer and use it in GitHub Desktop.
Sort woocommerce order items alphabetically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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