Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WooCommerce - Combine Sales Data From Multiple Stores WordPress

  • SOLVED

Hello

I have 10 separate woocommerce stores on separate servers. Now I need to log in to 10 different places to see sales data.

I need to create a small php file that will write number sales and Total Sales Amount:

secretsales.php?day=12-02-2015 = Orders: 15 , Sales Amount: 500 , Currency: USD

secretsales.php?month=02-2015 = Orders: 300 , Sales Amount: 10000 , Currency: USD

I will then have my own custom site like MyStats.com , where I use Google Charts do display the data in a nice way.

So what I need is the code for a tiny php file I can put perhaps in the woocommerce folder.


Best Regards, Petter Servenius

Answers (3)

2015-02-09

Ian Lincicome answers:

I don't know of a plugin. Are the sites on the same server? Are you using Multisite(WordPress MU)? If the answer to either one of those questions is yes, it will not be too difficult to create a solution. However, if the sites are not using MU and are on different servers, the solution gets a bit more complex. Not impossible, but probably worth more than $20 to be frank. I'll be happy for you if you get it done for that though. The largest challenge will probably involve cross domain scripting if the sites are on different servers, but answer those two questions above and I'll try to help. -Ian


FirstEntertainment comments:

Hi

It's on separate servers. I actually started to work a bit with google charts. They are really nice.. I think actually what I need is just some information of how to create some code that displays sales data.

I have updated the question regarding this =)


Ian Lincicome comments:

I see you edited your question to answer my questions. Thanks. I think your idea for is on the right track for an alternate solution. A plugin could be made to install in each WordPress site that collects the data from the sites and puts it all together in one report. It would be a bit of a project though I think, especially if you want charts. Do you want charts for all combined data or did you want to simply see existing woo charts for ea. site. If you want charts for combined data, that's more work obviously but not impossible. Of course I say nothing's impossible if you put enough time and/or money into it. I would probably charge around $500 to build this plugin, but I suspect someone will offer a less expensive solution if you give it some time. Let me know if you'd like to entertain my offer though. Good Luck -Ian.


Ian Lincicome comments:

If you want to do it on the cheap and can get someone from WP Questions to give you the code for querying the database and retrieving the data you want, that could work for you if you're a coder. I would put it together inside a small plugin though and not just a PHP file, that way you get all the WordPress functions and hooks.


FirstEntertainment comments:

I already have a coder that can use the data, and put the information in a database. That we then use with Google Charts.
He is not an expert in Woocommerce / Wordpress so I need an expert to make the simple code.

Actually I have used the exact method to export coupon sales data into my custom system. Basically it's just a file I created myself that works like this:

mysite.com/coupon-sales.php?id=12345
=> The PHP file only contains a number.

This would be the same type of system but slightly more complicated.

So actually, we don't really need a plugin, just a php file that we can put somewhere on the server :)

I will now add more money to this question, rewarded to the person who can write this code :)


FirstEntertainment comments:

"I would put it together inside a small plugin though and not just a PHP file, that way you get all the WordPress functions and hooks."

Not possibe to get the functions and hooks with just a simple file? Or perhaps easier with plugin.

Doesn't matter really.. any way that works is good :)

Could be like this then perhaps:

mysite.com/wp-content/plugins/custom-sales-exporter/secret-file.php?day=12-02-2015


Ian Lincicome comments:

It is easier and more standard to do with a plugin. For a WordPress expert, a plugin does not take much longer to make, maybe a few minutes longer when compared to a raw PHP file and the benefits are numerous. I'll mull this over for a bit and let you know if I can find the time to do it. I am a little busy at the moment, but if no one else answers your question before I have time to get to it, I'll try to help. If I wasn't already very busy, I'd do it now, but I am a bit in the weeds at the moment. I just thought I"d try to offer some advice real quick for now.


Ian Lincicome comments:

It is easier and more standard to do with a plugin. For a WordPress expert, a plugin does not take much longer to make, maybe a few minutes longer when compared to a raw PHP file and the benefits are numerous. I'll mull this over for a bit and let you know if I can find the time to do it. I am a little busy at the moment, but if no one else answers your question before I have time to get to it, I'll try to help. If I wasn't already very busy, I'd do it now, but I am a bit in the weeds at the moment. I just thought I"d try to offer some advice real quick for now.

2015-02-09

Bob answers:

Hi,

Here is the one way you can do it. You can use rest api to get data.

Do following process for each store
1. Login as admin to wordpress
2. Go to Users > Your Profile.
3. At very bottom you will see checkbox for "WooCommerce API Keys". check it and click update profile.
4. Now again scroll to bottom and note down "Consumer Key", "Consumer Secret"

Now go to [[LINK href="https://github.com/kloon/WooCommerce-REST-API-Client-Library"]]https://github.com/kloon/WooCommerce-REST-API-Client-Library[[/LINK]]
and download a zip file.

extract it on site where you wan to see all data. you will see example directory and example.php file in it.
Your developer can easily understand how to use it.

You need to place above keys in that file(example.php).

Then you can get sales report using code like this.

get_sales_report( $params = array( 'filter[start_date]' => '2015-01-01', 'filter[end_date]' => '2015-01-31' ) )

I can code for you if you wish. Please contact me at [email protected] or skype: thevaghlea

Regards,
Bob


Bob comments:

For more details please visit

[[LINK href="http://docs.woothemes.com/document/woocommerce-rest-api/"]]http://docs.woothemes.com/document/woocommerce-rest-api/[[/LINK]]
[[LINK href="http://woothemes.github.io/woocommerce-rest-api-docs/"]]http://woothemes.github.io/woocommerce-rest-api-docs/[[/LINK]]


FirstEntertainment comments:

Looks goood!

Quite simple.. maybe I can do this myself even. I'm gonna explore it for a couple of hours.. see what I manage to do =)


Bob comments:

Please note there are two versions of rest api

[[LINK href="https://github.com/helpforfitness/WooCommerce-REST-API-Client-Library-v2"]]https://github.com/helpforfitness/WooCommerce-REST-API-Client-Library-v2[[/LINK]]

Here is example of output at my server which show one month sales report and top sellers.
[[LINK href="http://wp-lovers.com/wpquestions/wpq-10596/example/example.php"]]http://wp-lovers.com/wpquestions/wpq-10596/example/example.php[[/LINK]]
The code used to fetch data is

$wc_api->get_sales_report( array( 'filter[date_min]' => '2015-02-01', 'filter[date_max]' => '2015-02-28' ))


There is minor bug there example code shows "start_date" and "end_date" it should be actually "date_min" and "date_max"


You can do plenty of things with rest api. get orders details, get order count, order notes, get coupon details, customer details,
even product details and reviews also.

That way you can make your chart very rich. :)

Sorry there is typo in my skype name it's - thevaghela


Bob comments:

You can first create multidimantional array or each store keys and url then and currency type.

Then loop through all and make object for each and fetch data using that object.


Bob comments:

Any luck? Need any help?


FirstEntertainment comments:

My coder is testing.. soon we will know if it works =)

2015-02-09

Reigel Gallarde answers:

Hi, I made a little plugin for your chart...

[[LINK href="https://github.com/reigelgallarde/wpquestions.com/blob/master/woocommerce-custom-sales-report.php"]]https://github.com/reigelgallarde/wpquestions.com/blob/master/woocommerce-custom-sales-report.php[[/LINK]]

simply upload this file on your plugins folder... locate in Plugins menu in Dashboard and activate WooCommerce Custom Sales Report...

after that you can use with this url, http://yoursite.com/wp-admin/admin-ajax.php?action=reports&range=last_month

action param is required.
range is default to 7days.

range can be 'custom', 'year', 'last_month', 'month', and/or '7day'.

if custom is used, you must supply start_date, with end_date but is not required.

sample calls...

admin-ajax.php?action=reports&range=last_month
admin-ajax.php?action=reports&range=custom&start_date=2015-02-03
admin-ajax.php?action=reports&range=custom&start_date=2015-02-03&end_date=2015-02-05

Now, you can put the plugin in your 10 sites.. and have any of it called by the other sites... :)

let me know if you have problems..

ps, I made it into a plugin cause I think it's best to do so. So we can just deactivate it whenever not needed...


Reigel Gallarde comments:

I forgot to mention the sample output would a a json format like this {"orders":"10","sales":"$5,806.05","currency":"USD"}


Reigel Gallarde comments:

here's a sample link from one of my demo site.... [[LINK href="http://printmydesigns.ml/wp/wp-admin/admin-ajax.php?action=reports&range=7day"]]http://printmydesigns.ml/wp/wp-admin/admin-ajax.php?action=reports&range=7day[[/LINK]]


FirstEntertainment comments:

Wow great. I'm gonna try the plugin! =)


Reigel Gallarde comments:

let me know if you have problems with the code :)