반응형
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 수업을 불러야 하나요?
API는 첫 번째 질문 이후 변경되었을 수 있지만, 이것은 훨씬 더 우아하고 WC 고유의 기능을 사용합니다.
$args = array(
'customer_id' => $user_id,
'limit' => -1, // to retrieve _all_ orders by this user
);
$orders = wc_get_orders($args);
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;
}
이 코드를 사용해 보세요.
언급URL : https://stackoverflow.com/questions/42643065/how-to-get-all-orders-of-current-user-in-woocommerce
반응형
'programing' 카테고리의 다른 글
상태를 어떻게 기다리죠? (0) | 2023.03.01 |
---|---|
JSON을 기존 개체로 역직렬화(Java) (0) | 2023.03.01 |
Angular를 사용하여 새 모델 저장JS 및 $리소스 (0) | 2023.03.01 |
Django REST Framework에서 커스텀 JSON을 반환하는 방법 (0) | 2023.03.01 |
powershell 3에서 json을 예쁘게 하다 (0) | 2023.03.01 |