Sort orders
1 2 3 4 5 6 7 8 |
// sort products by SKU (inside one order) add_filter('woe_fetch_order_products', function ($products, $order, $labels, $format, $static_vals) { usort($products, function($a, $b){ if ($a['sku'] == $b['sku']) return 0; return ($a['sku'] < $b['sku']) ? -1 : 1; }); return $products; },10, 5); |
1 2 3 4 5 6 |
// sort products by SKU , summary report add_action( 'woe_summary_before_output', function() { uasort( $_SESSION['woe_summary_products'], function ( $a, $b ) { return strcmp( $a['sku'], $b['sku'] ); } ); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// sort orders by billing full name using SQL filters add_filter('woe_sql_get_order_ids_left_joins', function ($joins) { global $wpdb; $joins[] = "LEFT JOIN {$wpdb->postmeta} AS billing_last ON (billing_last.post_id = orders.ID AND billing_last.meta_key='_billing_last_name')"; $joins[] = "LEFT JOIN {$wpdb->postmeta} AS billing_first ON (billing_first.post_id = orders.ID AND billing_first.meta_key='_billing_first_name')"; return $joins; }); add_filter('woe_sql_get_order_ids_fields', function ($fields) { return "ID AS order_id, CONCAT(billing_first.meta_value,billing_last.meta_value) AS billing_name"; }); add_filter('woe_sql_get_order_ids_order_by', function ($order_by) { return "ORDER BY billing_name"; }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// sort by usernames using SQL filters add_filter('woe_sql_get_order_ids_left_joins',function ($joins) { global $wpdb; $joins[] = "LEFT JOIN {$wpdb->postmeta} AS order_usernames ON (order_usernames.post_id = orders.ID AND order_usernames.meta_key='_customer_user')"; $joins[] = "LEFT JOIN {$wpdb->users} AS users ON users.ID = order_usernames.meta_value"; return $joins; }); add_filter('woe_sql_get_order_ids_fields', function ($fields) { return "orders.ID AS order_id,users.user_login AS username"; }); add_filter('woe_sql_get_order_ids_order_by', function ($order_by) { return "ORDER BY username DESC"; }); |