본문 바로가기
Frameworks/Wordpress 심화

[woocommerce] 주문 불러오기 wc get orders

by Nov19 2018. 12. 19.
반응형

[woocommerce] 주문 불러오기 wc get orders

// wc_get_orders()로 주문 내역 불러오기
$orders = wc_get_orders(
  array( 
     'billing_first_name' => 'John', 
     'date_paid' => '2016-01-01...2016-12-31`
  ) 
); 

// WC_Order_Query()를 이용해 args로 바로 생성해준다.
// 최근 10개의 주문을 가져와 주문 아이디를 담는 배열을 반환한다.
$query = new WC_Order_Query( 
  array( 
    'limit' => 10, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'return' => 'ids', 
  ) 
); 
$orders = $query->get_orders();

// WC_Order_Query()로 빈 객체를 생성하고 set()으로 주문 불러오기
$query = new WC_Order_Query(); 
$query->set( 'customer', 'woocommerce@woocommerce.com' ); 
$orders = $query->get_orders();

//Get an array of all of the current query variables set on the query object.
get_query_vars() 
//Get the value of a query variable or the default if the query variable is not set.
get( string $query_var, mixed $default = '' ) 
//Set a query variable to a value.
set( string $query_var, mixed $value ) 
//Get all orders matching the current query variables.
get_orders() 

// wc_get_orders( $args )로 주문을 불러올 때 args에 들어가는 내용들.
$args = array(
// 결제 완료 날짜
    'date_completed' => '1494971177...1494938777',
// 주문 날짜
'date_created' => '<' . ( time() - HOUR_IN_SECONDS ),
// 결제 날짜
'date_paid' => '2016-02-12',
// 이름
 'billing_first_name' => 'Claudio',
 'billing_last_name' => 'Sanches',
// 국가
'billing_country' => 'US',
// 사용자 아이디
'customer_id' => 12,
// 사용자 이메일
'customer' => 'woocommerce@woocommerce.com',
// 할인 가격
'discount_total' => 20.00,
// 결제 방법
'payment_method_title' => 'Check payments',
// 결제 방법
'payment_method' => 'cheque',
// 세금 포함여부
'prices_include_tax' => 'yes',
// 통화
'currency' => 'USD',
// 주문 아이디를 반환
'return' => 'ids',
// 랜덤으로 주문 반환
'orderby' => 'rand',
// 수정된 주문
'orderby' => 'modified',
'order' => 'DESC',
// Get second to fifth most-recent orders.
'limit' => 4,    
'offset' => 1,
// Second 3 orders.
'limit' => 3,
'paged' => 2,
// First 3 orders.
'limit' => 3,
'paged' => 1,
// 상태가 대기중인것
'status' => 'on-hold',
// 24시간내에 환불 된 것
 'type' => 'shop_order_refund', 
 'date_created' => '>' . ( time() - DAY_IN_SECONDS ),
// 우커머스 버전으로 검색
 'version' => '2.6.14',
// Get orders created through site checkout.
 'created_via' => 'checkout',
// 포스트의 parent 아이디로
'parent' => 20,
// 포스트의 parent 아이디로
'parent_exclude' => array( 20, 21 ),
// Get orders that aren't the current order.
'exclude' => array( $order->get_id() ),
// 최근 주문 3개
'limit' => 3,
);
$orders = wc_get_orders( $args );


//사용자 지정 쿼리
function handle_custom_query_var( $query, $query_vars ) {
	if ( ! empty( $query_vars['customvar'] ) ) {
		$query['meta_query'][] = array(
			'key' => 'customvar',
			'value' => esc_attr( $query_vars['customvar'] ),
		);
	}
	return $query;
}
add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', 'handle_custom_query_var', 10, 2 );

$orders = wc_get_orders( array( 'customvar' => 'somevalue' ) );





반응형

댓글