2017-12-02 8 views
1

고객이 취소 한 주문 수를 계산하고 관리 주문 화면에 표시하려고합니다.Woocommerce Admin 주문 주문 페이지에서 고객 취소 주문 수 표시

제 문제는 원격 고객을 위해 작동하지 못하게되어 스스로 해결할 수 있다는 것입니다 (current_user).

이 내 코드입니다 (다른 인터넷 검색 및 일부 작은 수정에서했다) :

function count_order_no($atts, $content = null) { 
$args = shortcode_atts(array(
    'status' => 'cancelled', 
), $atts); 
$statuses = array_map('trim', explode(',', $args['status'])); 
$order_count = 0; 
foreach ($statuses as $status) { 
    // if we didn't get a wc- prefix, add one 
    if (0 !== strpos($status, 'wc-')) { 
     $status = 'wc-' . $status; 
    } 
    $order_count += wp_count_posts('shop_order')->$status; 
} 
ob_start(); 
echo number_format($order_count); 
return ob_get_clean(); 
} 
add_shortcode('wc_order_count', 'count_order_no'); 

하고 어떤 도움이 많이 apreciated된다

// print the number 
function print_the_number() { 
echo do_shortcode('[wc_order_count]'); 
} 

// add the action 
add_action('woocommerce_admin_order_data_after_order_details', 'print_the_number', 10, 1); 

관리자의 수를 표시!

답변

0

현재 주문에서 고객 ID를 대상으로 지정해야합니다. 훨씬 간단한 방법으로 수행 할 수 있습니다.

이 작업을 시도해야합니다 :

add_action('woocommerce_admin_order_data_after_order_details', 'get_specific_customer_orders', 10, 1); 
function get_specific_customer_orders($order) { 

    $customer_orders = get_posts(array(
     'numberposts' => -1, 
     'meta_key' => '_customer_user', 
     'meta_value' => $order->get_customer_id(), 
     'post_type' => 'shop_order', 
     'post_status' => array('wc-cancelled'), 
    )); 

    $orders_count = '<strong style="color:#ca4a1f">' . count($customer_orders) . '</strong>'; 

    echo'<br clear="all"> 
    <p>' . __('Cancelled orders count: ') . $orders_count . '</p>'; 
} 

코드는 function.php의 활성 자식 테마의 파일 (또는 활성 테마)에 또는 플러그인 파일에 간다.

테스트를 거쳐 작동합니다.

+1

대단히 고마워요, 매력처럼 작동합니다! 실제로 당신의 방법은 훨씬 간단하고 명확합니다! – RwkY