How to get list of order id in woocommerce?

by filiberto , in category: PHP CMS , a year ago

How to get list of order id in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , a year ago

@filiberto 

To get a list of order IDs in WooCommerce, you can use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$args = array(
    'post_type' => 'shop_order',
    'post_status' => 'any',
    'fields' => 'ids',
    'posts_per_page' => -1
);

$orders = get_posts( $args );

foreach ( $orders as $order_id ) {
    echo $order_id . '<br>';
}


This code queries the WooCommerce database for all order posts (post_type = shop_order) and retrieves only the IDs of those orders. It then loops through the list of order IDs and outputs them in the desired format.


You can add this code to your theme's functions.php file or create a custom plugin to display a list of order IDs on a specific page or in the WordPress admin dashboard.

Related Threads:

How to get the order id from the order key in woocommerce?
How to list products by vendor id in woocommerce?
How to get woocommerce order details?
How to get the order date in woocommerce?
How to get order->price in woocommerce?
How to get updated woocommerce order data?