Skip Navigation

[Resolved] Custom Woocommerce store order and customer reports

This thread is resolved. Here is a description of the problem and solution.

Problem:

Query Woocommerce order posts with Views.

Solution:

Toolset plugin can query and display Woocommerce Order posts in frontend, see our document:

https://toolset.com/course-lesson/how-to-display-woocommerce-orders-on-the-front-end/

Relevant Documentation:

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 13 replies, has 2 voices.

Last updated by Luo Yang 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2253007

We would like to set up a page on the site that will display information pulled from Woocommerce store orders. We would like the output to be in Table format and include the following field data from our store orders:

1) Customer Last Name

2) Customer First Name

3) Order ID

4) User ID

5) User account initial registration date

6) Renewal date (not sure if we'll be able to do this or not. This relates to a question asked in the previous support ticket I just opened asking about setting up Custom Roles that get added to a user account upon purchase of specific products. If such Roles can be set up, then we would want to include this field showing the date that user's Role assignment expires)

7) Customer Street Address 1

8) Customer Telephone Number

9) Customer Zip Code

10) Customer E-Mail Address

Then, once this report is created with a front end page view, we would also like to add the ability to download the report in Excel or CSV format.

------------------------------------------------------------------

That's the first custom report we'd like to set up. The second custom report will also be in Table format and should include the following field data from our store orders:

1) Order ID

2) Order date

3) Customer Last Name

4) Customer First Name

5) Renewal Date (same as same field above)

6) Custom Role name

7) Product Ordered

Then, once this report is created with a front end page view, we would also like to add the ability to download the report in Excel or CSV format.

------------------------------------------------------------------

Then we would like a third custom report that should include the following field data from our store orders:

1) Order ID

2) Order date

3) Customer Last Name

4) Customer First Name

5) Order Total

6) Heard About? (This should be a custom field that we would like to add to the checkout process where we get customers to let us know where they heard about us) This report would show the data chosen in a selection box by the customer. I understand if this functionality is beyond what your plugin is designed to achieve.

7) SKU of the product ordered

8) Product attributes - We have a selection box for an attribute on all the products and would like to display what each customer selects here.

Then, once this report is created with a front end page view, we would also like to add the ability to download the report in Excel or CSV format.

--------------------------------------------------------------------

The the fourth and final custom report we would like to set up should include the following field data from our store orders:

1) Order ID

2) Order date

3) Customer Last Name

4) Customer Firest Name

5) Credit card type

6) Credit card number (should show only last 4 digits)

7) Order total

8) Heard About (This is the same as the custom field described above if that is doable)

Then, once this report is created with a front end page view, we would also like to add the ability to download the report in Excel or CSV format.

This report should also have a filter on the page that allows for the selection of a date range that will only display results for orders falling within the date range selected. It should show all orders by default and only apply the filter if a date range is added.

----------------------------------------------------------------------

Please let me know your thoughts on if Toolset would be able to achieve these results as is. As was the case with the support thread filed for achieving our desired Archives page output, this is another one where if you can show me how to do the first one, I should be able to figure out the rest on my own.

I'm just unclear on how to achieve these results from my efforts so far. I'm not seeing all the order data available when trying to create a View. I did see a documentation page on your site that showed me that I have to enable the Woocommerce related fields in Settings | Front-End Content | Hidden custom fields. I have done that already, but I'm not seeing where these fields are now available.

I have set up a page on the site titled Manage Members where I would like to display the first report detailed above. But I can't figure out how to get this content on that page. When i click on Fields and Views in the Classic Editor, I'm not seeing these fields available there. I didn't see anything in the Block Editor either. So I went to create a new View under Toolset first, figuring maybe I need to create the View first and then place it on the Page. So under Toolset | Views, I tried to create Manage Members there. I didn't get very far there because this is first attempt I'm making setting up a View and I'm finding it very confusing. Any assistance would be appreciated. If this is something where we'd need to hire one of your contractors to achieve this, let me know. But again, if you can just give me a nudge in the right direction for how to best go about setting these up, I think I can figure out the rest.

#2253317

Hello,

Toolset plugin can query and display Woocommerce Order posts in frontend, see our document:
https://toolset.com/course-lesson/how-to-display-woocommerce-orders-on-the-front-end/

And you can also add custom fields into Woocommerce Order post type:
https://toolset.com/course-lesson/creating-custom-fields/

And display those tables as what you want in frontend.

But there isn't such kind of built-in feature to export the results into Excel or CSV format, you might consider custom codes or other plugins, for example:
hidden link

#2253717

OK, I have made some progress on this based on the first course lesson page you provided. But I'm finding that the setup doesn't exactly match the steps in the lesson. When I create the view, there are many steps not included in the lesson where I was guessing as to what the right thing to do would be. I've done a fairly good job of that to create the following page:

hidden link

This is really close to what we want.

The first problem on this page is the column headers are showing the field names as they are defined in the system. Is there any way to change how those are listed to a non-system version. For example, the first field says "_billing_last_name". We'd like it to say "Last Name" instead. If you could show me if there is a way to change this label, I could do it for all of the field names.

The second thing I'd like to ask about on this is if there is any way to style the results to show each row with an alternating background color to improve readability of the results. The page we are trying to emulate can be found here:

hidden link

See how one row is gray, then one row is white? That's what I'd like to achieve, but I'm not sure how to provide unique CSS classes for the rows on the table or maybe something like view-table-row-odd and view-table-row-even as classes so I can set the backgrounds once each as CSS for how they alternate.

The third things I'd like to ask about is how we edit what's been created to change fields if necessary. When we're on the Edit View page for this view, I'm seeing the Loop Editor that shows what I've set up as code. Is that what I use to add or remove fields? I'm seeing that I can edit by clicking the Loop Wizard button. Is that the correct way?

I'm also seeing that a Template was created called Loop item in Manage Members . But when I go to edit that with the Edit in Block Editor button, it takes me to an edit page where everything is only showing shortcodes for the chosen fields and editing here seems very confusing.

I just wanted to make sure of the right way to do this. If I edit using the Loop Wizard, will the Loop item in Manage Members template automatically update from that?

#2253727

As for the feature to export the results as CSV or Excel, I'd like to propose this as a feature request for you. When people use your plugin to create order reports like this, being able to export those results is very helpful. In the edit View screen you could just add checkboxes that can be selected to append buttons to the end of the view that allow for exporting the data. If people want this, they just check one or both of the checkboxes. If they don't then they leave the checkboxes unchecked.

Go here to see an example of what I mean on another report we are going to be trying to emulate here:

hidden link

Scroll to the bottom of the page and you'll see small buttons added that allow the data to be downloaded. That would be a very nice feature for you to add IMO.

I'll take a look at the plug-in you suggested as well but I think this would be a great addition for your plugin.

#2253853
table-header.jpg

Q1) The first problem on this page is the column headers are showing the field names as they are defined in the system.
You can change the table header text manually, if you are using classic editor to setup the view, you just need to edit the text in section "Loop Editor", see my screenshot table-header.JPG

Q2) The second thing I'd like to ask about on this is if there is any way to style the results to show each row with an alternating background color to improve readability of the results.

You can use [wpv-item] shortcode to output different result for each row, for example:

...
<wpv-loop>
    [wpv-item index=odd]
         add your content for odd index
    [wpv-item index=even]
         add your content for even index
        
 </wpv-loop>
...

See our document:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154400

Q3) I suggest you use classic editor to setup the post views in table layout mode, for example:
1) Dashboard-> Toolset-> Settings-> General
in section "Show both the legacy and Blocks interface and let me choose which to use for each item I build"

2) Dashboard-> Toolset-> Views, setup the post views, se the screenshot I mentioned above

Q4) For the csv export issue, you can add a feature request here, our developers will evaluate it.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#2253901

1) Your solution here worked perfectly. Thanks!

2) I'm not fully clear on how to set up the odd even code you showed me here. Here is the table code that I have:

<table width="100%">
<thead>
<tr>
<th>[wpv-heading name="post-field"]Last Name[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]First Name[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]Order ID[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]Customer ID[/wpv-heading]</th>
<th>[wpv-heading name="post-date"]Post date[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]Address[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]City[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]Zip[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]Phone[/wpv-heading]</th>
<th>[wpv-heading name="post-field"]E-Mail[/wpv-heading]</th>
</tr>
</thead>
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr>
[wpv-post-body view_template="loop-item-in-manage-members"]
</tr>
</wpv-loop>
</tbody>
</table>

Can you show me where I'd add the <wpv-loop>, [wpv-item index=odd] and [wpv-item index=even] bits in here? Since the content is being generated in the loop-item-in-manage-members template, I don't see how to do odd and even lines here. If I put the loop in both odd and even, I'm thinking it will just show all rows twice with one full list after the other full list. The rows wouldn't alternate between odd and even.

3) It looks like I have the settings set up as you recommended. It seems to be working editing using the Loop Wizard so far.

#2253917

I have already provided the example codes in above answer:
https://toolset.com/forums/topic/custom-woocommerce-store-order-and-customer-reports/#post-2253853

In your case, it should be like these:

...
<wpv-loop>
<tr>
[wpv-item index=odd]
add your content for odd index
[wpv-item index=even]
add your content for even index
</tr>
</wpv-loop>
...

It is only an example, you need to customize above codes with HTML + CSS codes

#2253947

It currently is coded as:

<wpv-loop>
<tr>
[wpv-post-body view_template="loop-item-in-manage-members"]
</tr>
</wpv-loop>

If I do the following:

<wpv-loop>
<tr class="odd">
[wpv-item index=odd]
[wpv-post-body view_template="loop-item-in-manage-members"]
</tr>
<tr class="even">
[wpv-item index=even]
[wpv-post-body view_template="loop-item-in-manage-members"]
</tr>
</wpv-loop>

Won't that just execute the full loop-item-in-manage-members and show ALL results as odd and then show ALL results again as even? Or will it know to execute one line as odd and then one line as even? That's the part this is confusing me about this.

I went ahead and tried this and it didn't work as I thought it would. It is adding the class="odd" and class="even" to my TR tags, but the lines from the loop item are not working as hoped or predictably. We have 3 rows on this right now. All three rows are showing under odd TR's and none of them are showing under even TR's. What's weird is the source code on the page is showing the TR's as odd, even, odd, odd, even. The odd ones all have the field data within them, but the even ones are empty.

Go here to see the page:

hidden link

Obviously I'm doing something wrong. I'm just unclear on how these shortcodes work.

#2253949

You can provide a test site with the same problem, I can setup a demo in it, thanks

#2254483

Thanks for the details, I have done below modifications in your website:
Edit the post view "Manage Members":
hidden link
in section "Loop Editor", change the codes as below:

...
		<wpv-loop>
                                 [wpv-item index=odd]
			<tr class="odd">
				[wpv-post-body view_template="loop-item-in-manage-members"]
			</tr>
                                 [wpv-item index=even]
			<tr class="even">
				[wpv-post-body view_template="loop-item-in-manage-members"]
			</tr>
		</wpv-loop>
...

Please test again, check if it is fixed, thanks

#2254563

That worked! Thanks a bunch. You can see the updated display here:

hidden link

I still have some additional styling to do to make the table look nicer, but the alternating rows is working now. Now I have to copy what you did here and do the same thing in four or five other views that I've built.

Note that when I initially had my client here purchase Toolset, I wasn't expecting that we'd be able to accomplish these Woocommerce store order reports, so this is AWESOME that we're getting this far with it. Know that the work I'm having you guys do on this will lead to at least 3 more clients purchasing your plugin. I've already seen enough success with it that I'm confident we'll be able to achieve enough of their goals for me to recommend this. This is making it possible to migrate sites that are HEAVILY dependent on Drupal Views over to WordPress and is extremely impressive work. Thanks.

#2254569

My issue is resolved now. Thank you!

#2254571

I assume the original question of this ticket is resolved, if there are other new issues, please create new ticket for them, thanks

#2254573

Closing here