• Resolved free3dart

    (@free3dart)


    I am trying to export customer data as xml, and using the Customer Total Orders field, though I get the total orders, the total includes the cancelled and pending payemnts but I need total orders for each customer only for the orders paid and currently processing, and those marked as completed. though I have set the Order statuses to Processing

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    please, open section “Misc Settings” and add this PHP code.
    thanks ,Alex

    add_filter("woocommerce_customer_get_order_count", function($value,$customer){
    global $wpdb;
    $statuses = array("wc-processing","wc-completed");
    return $wpdb->get_var(
    				"SELECT COUNT(*)
    				FROM $wpdb->posts as posts
    				LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
    				WHERE   meta.meta_key = '_customer_user'
    				AND     posts.post_type = 'shop_order'
    				AND     posts.post_status IN ( '" . implode( "','", $statuses) . "' )
    				AND     meta_value = '" . esc_sql( $customer->get_id() ) . "'"
    			);
    },10,2);
    Thread Starter free3dart

    (@free3dart)

    Thank you so much, Works Perfectly. Thanks again.

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Customer Total Order only for the processing or completed orders’ is closed to new replies.