Order Count and Total Spent on the Account Dashboard
Shows customers how many orders they have placed and how much they have spent in total, a nice touch for loyalty or VIP programmes.
Opens WPIDE on
Code
add_action( 'woocommerce_account_dashboard', function () {
$user_id = get_current_user_id();
$count = wc_get_customer_order_count( $user_id );
if ( ! $count ) {
return;
}
printf(
'<p class="wpide-account-stats">%s</p>',
wp_kses_post( sprintf( 'You have placed <strong>%1$d</strong> order(s) with us, totalling <strong>%2$s</strong>. Thank you!', $count, wc_price( wc_get_customer_total_spent( $user_id ) ) ) )
);
}, 5 );
Notes
Uses WooCommerce's cached customer totals, so it adds no heavy queries.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.