WooCommerce is an e-commerce plugin for WordPress(WP) that powers millions of online stores worldwide. It is one of the most accessible and affordable shopping systems – hence its prevalent use.
WooCommerce stores are loaded with a lot of data that can be used to make actionable decisions and produce positive outcomes. Since machine learning is transforming many industries like e-commerce, WooCommerce’s bountiful data store is ideal for this tutorial.
Thankfully, there is a lot of rich data stored in WP tables that can yield valuable insights into customers, products, carts, and orders. Don’t let your imagination limit what you can do with the data gathered from WooCommerce. Be ambitious and explore the vastness of your WP data.
WooCommerce Data Analysis: The Possibilities Are Endless!
With a robust Data Science plan, you could develop custom Machine Learning models to fit your use case. The below are some ideas that can be a guide for your data analysis journey:
Customer Recommendation Engine
Understanding customer shopping behavior is one of the most important uses of your WooCommerce data. It can help you build a recommendation engine that will target the right customers and increase conversions.
With machine and deep learning algorithms, you can track customers’ shopping behavior and use the patterns generated to make valuable recommendations.
Product Analysis and Merchandising
Retailers who stay ahead in the industry are those who make sweeping changes based on customer feedback. However, we now live in an era where rich data can speak to us more clearly than customers!
Keeping track of returns and complaints using machine learning can produce more profound insights into stocked products. This analysis can help detect anomalies like warranty claims, complaints, and returns. Managers can make actionable decisions about merchandising based on the data analyzed.
With machine learning, data analysis can produce models that can keep stock levels at the optimal rate. Besides, these types of algorithms also track seasonal shoppers, their buying patterns, and other factors that can increase or reduce demand.
For as long as the retail industry has been around, Sentiment Analysis has been the primary measure of customers’ satisfaction.
Today, the rise of Machine Learning and Natural Language Processing (NLP) has made Sentiment Analysis more reliable. Also, social media pages are a rich source of data that can be combined with your WooCommerce data to produce informed insights into customers’ sentiments.
WooCommerce API and Your Jupyter Notebook
There are so many more use cases. But before you begin your analysis, you must formulate a plan which will help guide you. For example, if inventory management is the main reason for your research, then create a data analysis plan based on this target. What this means is that you will only need to create a DataFrame for WooCommerce products.
Here’s a quick guide on how to pull data from WooCommerce into Jupyter notebook:
1. Import modules into Jupyter
To get started, I’ll import Pandas, JSON and REQUESTS!
WooCommerce API data is delivered as a JSON object, and the python JSON module has all the functions and methods necessary to work with JSON on Jupyter. Also, since I will be sending a GET request in this tutorial, I will import the REQUEST python module as well.
import requests import json import pandas as pd
2. WooCommerce API endpoint structure
From the WooCommerce settings page, I will activate API access and create a consumer key and secret. Without these access keys, my GET request will return a 401 error.
Safety note: I recommend you only generate keys with ‘read’ access.
The WooCommerce API URL is structured as below:
Website URL – your URL (https://example.com)
Request endpoint – a standard endpoint for WooComemrce version 3 (/wp-json/wc/v3) followed by the data class. In this tutorial, I will pull data from the orders table and append /orders to the URL.
Parameters – The page value and order status are great ways of filtering the results in the get request URL.
Page: Data returned from this API is paged, and I can make a maximum request of 100 per page.
Status: Since I’m interested in only completed orders, the order’s status is another parameter I will specify in the URL.
Access tokens – these are keys generated on the WooCommerce settings page. Without access tokens, a 401 error will be returned. Passing your security keys in the URL of a request isn’t the best practice. I’m using this method for this tutorial only.
json_orders = pd.read_json('https://example.com/wp-json/wc/v3/orders?consumer_key=ck_12345&consumer_secret=cs_12345&satus=completed&page=1') page = 1 json_orders = pd.read_json(url + str(page)) print(json_orders.to_string())
3. Gather information about the data
My DataFrame has been created and loaded with a hundred orders from WooCommerce. Of course, you will need more orders to carry out any meaningful data analysis. But this tutorial only shows the method used to get and display the data.
I’ll take a closer look at my data columns to determine what stays and what goes.
#Check columns print(json_orders.columns)
4. Drop irrelevant WooCommerce columns
One thing is clear from looking at the columns in this list; there are just too many columns that I don’t need! So, I’ll save myself some time and assign the columns I need to a new DataFrame.
My data needs are not much. I’m not doing a predictive analysis or creating a machine learning model. I’m simply trying to gather some information from the WooCommerce data. All I need are the order amount, date of each order, and customer_id. These are sufficient to answer the most basic questions.
orders = pd.DataFrame(json_orders, columns=['customer_id', 'date_created', 'total']) orders
That’s it! Your WooCommerce data is loaded and ready for use. Next step is cleansing the data.
To efficiently clean any data set, you first have to understand the data. Subject matter expertise does make a lot of difference when analyzing data, and data scientists are typically encouraged to specialize in a field.
You can also export a CSV from WooCommerce and load it into Jupyter. However, this approach requires access to the backend, which some data analysts may not have. Whatever method you use, the vital thing to remember is that this data opens a window to the heart of the business. When machine learning engineers create intelligent systems for e-commerce businesses, an increase in sales and profits is always the result.