$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - How remove trashed WooCommerce orders from wc_get_orders() result?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - How remove trashed WooCommerce orders from wc_get_orders() result?

matteradmin9PV0评论

I like to use wc_get_orders() function to get WooCommerce orders in front end.

Here is my code snippet to get orders.

$args = array(
    'customer_id' => get_current_user_id(),
    'return' => 'ids',
    );
$customer_orders = wc_get_orders( $args );

var_dump($customer_orders);

The above code will return all orders of current users.

The issue is, the wc_get_orders return all orders including trashed orders. Is there any option to exclude trashed orders?

More details about this function are available in this link.

I like to use wc_get_orders() function to get WooCommerce orders in front end.

Here is my code snippet to get orders.

$args = array(
    'customer_id' => get_current_user_id(),
    'return' => 'ids',
    );
$customer_orders = wc_get_orders( $args );

var_dump($customer_orders);

The above code will return all orders of current users.

The issue is, the wc_get_orders return all orders including trashed orders. Is there any option to exclude trashed orders?

More details about this function are available in this link.

Share Improve this question asked Jan 4, 2019 at 12:28 Sarathlal NSarathlal N 1211 silver badge5 bronze badges 1
  • Sorry. Previously, I got wrong output due to some error. Now I confirmed that the wc_get_orders() function will exclude trashed orders. – Sarathlal N Commented Jan 6, 2019 at 12:15
Add a comment  | 

1 Answer 1

Reset to default 1

Use Wp_Query instead it will give you the option to get data with status.

$args = array(
  'post_type' => 'shop_order',
 'posts_per_page' => '-1',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future','private', 'inherit', 'trash')  
);

$my_query = new WP_Query($args);

$orders = $my_query->posts;

echo "<pre>";
print_r($orders);
echo "</pre>";

it will display All of your order.

hope this will help you out.

Post a comment

comment list (0)

  1. No comments so far