如何获取woocommerce中当前用户的所有订单
问题描述:
我想获取当前用户在插件功能中所做的所有订单。如何获取woocommerce中当前用户的所有订单
我使用这个:
function get_all_orders(){
$customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
'numberposts' => $order_count,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types('view-orders'),
'post_status' => array_keys(wc_get_order_statuses())
)));
return $customer_orders;
}
这种运作良好,里面的主题,但里面自定义插件不返回任何东西。 我做错了什么?我应该先拨打一些WooCommerce课程吗?
答
if (!class_exists('WooCommerce')) :
require ABSPATH . 'wp-content/plugins/woocommerce/woocommerce.php';
$orders = get_all_orders();
endif;
function get_all_orders() {
$customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types('view-orders'),
'post_status' => array_keys(wc_get_order_statuses())
)));
return $customer_orders;
}
试试这个代码。
我已经在一个插件中测试了你的代码,激活了它,并且在前端没有任何需求的情况下完美运行。你的问题在其他地方... – LoicTheAztec