admin管理员组文章数量:1130349
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
1 Answer
Reset to default 1Use 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.
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
1 Answer
Reset to default 1Use 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.
本文标签: plugin developmentHow remove trashed WooCommerce orders from wcgetorders() result
版权声明:本文标题:plugin development - How remove trashed WooCommerce orders from wc_get_orders() result? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749045161a2307749.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论