Skip to content
Advertisement

Sort Orders IDs alphabetically based on the shipping last name in Woocommerce

I need to sort my $order_name (more specifically $order_shipping_last_name) alphabetically. I’ve tried many different basic php sort() methods, in many different places, and can’t get this to work. I’m assuming I’m missing something?

In my code, get_all_orders_that_have_a_product_variation( $product_id ); function comes from this answer code that allow to get an array of orders IDs from a variation ID…

The list is output as $variables['order_list'] near the bottom.

JavaScript

Advertisement

Answer

This needs to be done before in the function where you get the Orders IDs, changing a bit the included SQL query, this way:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

The change is made on sorting the Orders IDs array using the shipping last name.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement