I would like to know every customer's total number of previous orders so we can reward our high value customers. We use the official WooCommerce plugin “WooCommerce Print Invoices/Packing Lists“ by SkyVerge to print an invoice for each order. I am trying to get that customer's total number of previous orders to appear on this invoice, so we can reward them accordingly.
This is just the simplest solution I can think of. If anyone has any other methods for quickly seeing how many previous orders any given customer has made, I'd be happy to hear it... For example would it be easier to go into the Admin Confirmation Email Notification?
I have tried the following snippet but get an "array" error:
function sv_wc_pip_sample_add_custom_meta( $type, $action, $document, $order ) {
$order_id = is_callable( array( $order, 'get_id' ) ) ? $order->get_id() : $order->id;
echo "<br><br>Previous orders by this customer: ";
$numorders = wc_get_customer_order_count( $user_id );
echo $numorders ;
global $count_real;
$args = array(
'customer_id' => $my_user_id_itp,
'post_status' => 'any',
'post_type' => 'shop_order',
'return' => 'ids',
'limit' => -1
);
$count_real = 0;
$count_real = count( wc_get_orders( $args ) ); // count the array of orders
echo $count ;
echo $wc_get_orders ;
echo $args ;
}
add_action( 'wc_pip_after_customer_addresses', 'sv_wc_pip_sample_add_custom_meta', 10, 4 );