Skip to content
Advertisement

Get a custom field count for Woocommerce orders

Hi I am working on woocommerce

I have added custom fields in Woocommerce for orders which is an Agent name each order is assigned with an Agent.

I would like to get Agent name with its total order count.

I have created custom widget and its working well , just issue with the agent name its coming every time. I need agent name only one time and its total count.

Below is the code I have tried:

JavaScript

But it displays output like below :

Agent Name Order Count
Agent1 1
Agent1 2
Agent2 3
Agent1 4

My expected output :

Agent Name Order Count
Agent1 3
Agent2 1

Can you guys please help me on this ? What I am missing ?

Advertisement

Answer

This can be done with a very light and simple SQL query, that will compact your function:

JavaScript

Code goes in function.php file of your active child theme (or active theme).

Tested and works.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement