// specify the type of order you need. (delete any item that you dont need)
$order_status = array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed');
$user_orders= wc_get_orders( array(
'meta_key' => '_customer_user',
'meta_value' => $current_user->ID,
'post_status' => $order_status,
'numberposts' => -1,
) );
$order_statuses = wc_get_order_statuses();
$order_statuses = array_diff_key($order_statuses, array(
'wc-failed' => '',
// add any other statuses you want to exclude (you just need the key)
)
);
$query_args = array(
'limit' => -1, // to retrieve all
'customer_id' => 12, // or use 'customer' => '[email protected]'
'status' => array_keys($order_statuses) // use only the keys
);
$orders = wc_get_orders($query_args);
2条答案
按热度按时间2ul0zpep1#
您可以通过检查订单的“后状态”来获取任何类型的用户订单,如下所示:
然后检查结果并做一些事情...
e5nqia272#
这就是我如何找到一种方法来做到这一点,即使其他插件添加了新的状态类型:
这将为您提供该客户的所有订单,而不包括失败的订单。