1

I want to bulk update orders, But update seems going from oldest order to latest. I want to make it to update from latest to oldest.

I tried php array_reverse, can be see in code

add_filter( 'handle_bulk_actions-edit-shop_order', 'update_all_handle_bulk_action_edit_shop_order', 10, 3 );
function update_all_handle_bulk_action_edit_shop_order( $redirect_to, $action, $post_ids ) {
    if ( $action !== 'update_all' )
        return $redirect_to; // Exit


    $processed_ids = array();

    foreach ( $post_ids as $post_id ) {
       // do code
        } 

        $processed_ids[] = $post_id;
        
    }
$reversed_processed_ids = array_reverse($processed_ids);
    return $redirect_to = add_query_arg( array(
        'update_all' => $action,
        'processed_count' => count( $processed_ids ),
        'processed_ids' => implode( ',', array_reverse($processed_ids) ),
        'orderby' => 'date',
        'order' => 'desc',
    ), $redirect_to );
}
  • 1
    Doesn't the action take place inside your foreach loop? In other words, before going through the foreach, you could reverse the `$posts_ids` – 7uc1f3r Oct 18 '21 at 13:46

0 Answers0