B
B
basist_rv2016-10-12 00:46:50
WordPress
basist_rv, 2016-10-12 00:46:50

Woocommerce how to get the sum of all products ordered by a customer for all time?

What function, to display the sum of all orders in the client's account, shoveled the entire Internet, but unfortunately did not find the answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2016-10-12
@deniscopro WordPress Tag Curator

It?

public function get_customer_total_order() {
    $customer_orders = get_posts( array(
        'numberposts' => - 1,
        'meta_key'    => '_customer_user',
        'meta_value'  => get_current_user_id(),
        'post_type'   => array( 'shop_order' ),
        'post_status' => array( 'wc-completed' )
    ) );

    $total = 0;
    foreach ( $customer_orders as $customer_order ) {
        $order = wc_get_order( $customer_order );
        $total += $order->get_total();
    }

    return $total;
}

Source .
In the desired WooCommerce template call
Сумма всех заказов: <?php echo get_customer_total_order(); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question