WordPress is the most popular CMS in use today. why? Because you can easily integrate it with thousands of tools to improve your website’s performance and functionality.
Although these tools cover a wide range of industries, users are consistently impressed by the number of tools available for e-commerce. One of the most powerful e-commerce tools is the WooCommerce API.
Understand the WooCommerce API
WooCommerce’s API has three main components. To understand how powerful this API is, let’s look at each component individually.
REST API
WooCommerce’s REST API allows users to access your WooCommerce storefront from outside your website. This design makes your store accessible from other internet applications, such as Shopify, for example.
eventually, REST API Easily manage your store. Accessing your WooCommerce store from other apps’ dashboards also gives you access to full WooCommerce management functionality.
Legacy API
Previously, enabling legacy APIs was the way to activate WooCommerce’s APIs. However, this part of the process is becoming obsolete in recent versions.
The latest version is WooCommerce REST API. Integrates directly with WordPress API. Legacy APIs are older versions of WooCommerce. WooCommerce tends to launch legacy APIs by default, so users should double-check their settings.
Webhook
Webhooks allow WooCommerce to “call” other apps. For example, if you want actions performed in other apps to trigger actions in WooCommerce, you can use webhooks.
The API accomplishes this using URLs. You can send notification alerts to specific URLs through the API. These URLs can trigger events on one site and trigger other actions on another site or page.
Sell your products online with confidence
Officially recommended by WooCommerce, our hosting is made for online businesses like yours.
WooCommerce API Key Terms
As you read WooCommerce’s API documentation, you’ll come across terms that are specific to WooCommerce. Let’s review these terms and definitions to help you navigate the API process.
Request/response format
This indicates the format that WooCommerce uses to send certain types of data. Being aware of different data types is important because certain URLs and triggers will not work unless the data is received in the proper format.
The standard format for most data within the WooCommerce API is JSON. Calendar dates are returned as integers, and any numbers (amounts, prices, totals, etc.) are included in the text string, defaulting to two decimal places. If left blank, an empty string or “null” will be returned.
certification
The authentication process enables WooCommerce API integration. Users can use API keys to connect APIs to other platforms.
To generate a WooCommerce API key, you need to access your settings. WooCommerce users have two keys available to them: a private key and a consumer key.
Consumer keys are also known as general keys or API keys. These keys are issued to users from various platforms. WooCommerce API keys allow you to connect to other platforms like WordPress, Shopify, and more.
Private keys work similarly for specific apps and platforms. When you connect a third-party tool or app to WooCommerce, the public or consumer key acts as the “username” for your login credentials, and the private key acts as the password.
end point
From an API technology perspective, an endpoint is the point at which an API interacts with another app or platform. Examples of endpoints are URLs for specific platforms such as Shopify or Facebook.
WooCommerce API setup
The process of setting up WooCommerce API is relatively simple. Follow the steps below to link all your tools to your platform and transform your customers’ e-commerce shopping experience.
You need to navigate to the following menu in your WordPress dashboard.
WooCommerce > Settings > Advanced Settings > Legacy API
There is a checkbox that indicates whether the API is enabled. Make sure the checkbox is selected and click Save Changes to enable API access.
How to create an API key in WooCommerce
API keys are the backbone of WooCommerce API functions. Create tools to connect your favorite tools and platforms. To do this, follow the steps below.
1. Add a key
You must create a new key for each app or platform that connects to WooCommerce. The API generates a consumer key and private key for each new connection you create.
To add a key, you need to go to the REST API menu. Here’s how to find it:
WooCommerce > Settings > Advanced Settings > REST API
Once you’re there, click Add key.
2. Configure key settings
[キーの追加]Once you click , you’ll need to make a few decisions. For each key you create, you must configure the following settings:
- explanation – Now give each key a “name” for the corresponding platform to help organize it.
- owner – Assign keys to specific users within your team who are responsible for them.
- authority – These determine what functionality is given to this particular key. For example, if you need a specific key to delete or adjust data, you need to grant it “read/write permissions”.
3. API generation
Once the settings are complete, press the “Generate Key” button at the bottom of the screen. The next page contains the consumer key and private key, as well as his QR code for this connection.
Once you exit the API generation page, you cannot return. Therefore, copy these keys to another Word or Notes document and keep them.you need them to connect to WooCommerce setup.
4. Connect to third-party apps using keys
Now that your API key has been generated, you can start connecting to third-party apps and platforms known as “API clients.” You will need to follow the steps on both sides of the connection between WordPress and the WooCommerce menu in the app of your choice.
Each platform is different, so you will need to access the help resources for that specific platform. Look for tips on how to access app credentials.
Most platforms offer multiple authentication types. We recommend choosing basic authentication.
Copy and paste your general or consumer API key into the Username bar and use your private key as your password. This allows you to connect WooCommerce to any of your other powerful e-commerce tools. The next step is to start making API requests.
How to make a WooCommerce API request
API requests are where the magic happens. These requests enable all the “cool” features that make your life easier. These requests come in two forms: GET or PUT. To configure between tools, follow the steps below.
1. Test the GET request
GET requests, as the name suggests, are useful for retrieving data from other sources. A real e-commerce example is getting a list of WooCommerce products. This requires some technical knowledge, but if you follow the instructions you should be fine.
To run this GET function, you must enter the following URL:
https://yoursite.com/wp-json/wc/v3/products
Naturally, you’ll need to enter the URL where it says “Your site.” This GET will retrieve all the data for the products listed in WooCommerce.
The WooCommerce API integration returns this data in JSON format. If done correctly, the platform that connects to WooCommerce will parse this data and convert it into a format that is easy to use for end users.
If you run this GET function and receive a 401 or any other numbered code, it means there is some kind of error. To troubleshoot, you may need to go back or look further at your platform’s help resources. If your GET request is successful, you’ll see a JSON string in the Body section of your dashboard.
2. Test the PUT request
You should also check the PUT request using the data from the GET request from step 1. In this example, assume that the product you are using for this request has a product ID of 101. To perform a GET request, the URL is slightly different.
https://yoursite.com/wp-json/wc/v3/products/101
The process of making this a PUT function instead of a GET is easy.
- There is a drop-down menu next to the URL field.
- Select it and change the function from GET to PUT.
- In the body pane of the dashboard, select the Raw option.
- Open the Text dropdown menu and select JSON.
Once these steps are complete, you can make your request. An example of using this would be to change the price of product #101. To do this, enter the following text:
"regular_price": "50"
after that,[送信]Click to publish your results to your site.
Convenient e-commerce API requests
Some API requests are useful for e-commerce stores. It may take some research to find the API requests that do exactly what you’re looking for, but we’ve listed some basic requests below to get you started.
GET request
Here are some GET request URLs that you can perform on your e-commerce store.
- Get all products: https://yoursite.com/wp-json/wc/v3/products/
- get all customers: https://yoursite.com/wp-json/wc/v3/customers/
- get 1 customer:ID}
- Get all product categories: https://yoursite.com//wp-json/wc/v3/products/categories
- Get product variations. ID}/variation/variation ID
- GET A SINGLE PRODUCT:ID}
PUT request
Here are some basic PUT requests that are useful for your store.
Update product attributes (color, size, etc.).
"id": 1,
"name": "Color”,
"slug": "pa_color",
"type": "select",
"order_by": "name",
"has_archives": true,
"_links":
"self": [
"href": "
],
"collection": [
"href": "
]
Update customer’s full name
"first_name": "John",
"last_name": "Doe"
Update product prices for variants
"regular_price": "81"
Update prices and quantities in one request
"regular_price": "50",
"stock_quantity": 30
Update your shipping address
"shipping":
"first_name": "Jane",
"last_name": "Doe",
"company": "Jane Doe Co",
"address_1": "361 Outside Rd",
"address_2": "Suite 101",
"city": "Las Vegas",
"state": "NV",
"postcode": "89102",
"country": "US"
Update product review
"id": 20,
"date_created": "2018-09-08T21:47:19",
"date_created_gmt": "2018-09-09T00:47:19",
"product_id": 31,
"status": "approved",
"reviewer": "Claudio Sanches",
"reviewer_email": "john.doe@example.com",
"review": "Now works just fine.",
"rating": 5,
"verified": true,
"reviewer_avatar_urls":
"24": "
"48": "
"96": "
,
"_links":
"self": [
"href": "
],
"collection": [
"href": "
],
"up": [
"href": "
],
"reviewer": [
"embeddable": true,
"href": "
]
Advanced usage of WooCommerce API
In addition to the basics, users can also leverage the WooCommerce API to handle some advanced features of their e-commerce store. Some of WooCommerce’s advanced features include:
- custom pagination – WooCommerce API allows users to create custom product numbers per page to match the style and layout of your website
- Webhook – Users can program WooCommerce webhooks to trigger events on other websites. Ecommerce storefronts can use this to help: WooCommerce shipping optionspackaging, return procedures, etc.
- asynchronous task – Stores can independently launch asynchronous tasks after an order has been paid or a customer has created an account with your brand.
- Filtering and sorting data – you can add Custom fields for WooCommerce products Improve your customer experience by implementing custom sorting functionality
WooCommerce best practices and tips
WooCommerce API gives you great freedom to customize your e-commerce store. It’s important not to over-customize or add too many bells and whistles to your e-commerce store. Here are some best practices to keep in mind when customizing your e-commerce store.
Use plugins
If you only want to make small changes to your store, consider using a plugin. Everything is handled within the dashboard, so no additional code or text strings are required.
JetPack for WordPress is a useful plugin for basic customization of WooCommerce. This option is best if the updates you want to make only involve changes to stylesheets or CSS feeds.
moreover, Many CSS plugin options Can be used if you want to have global CSS that will not be lost when changing the active theme or child theme.
Use a child theme
If you update your stylesheet or CSS, it may be reset every time your website is updated. To maintain your customizations as WordPress continues to update your site, consider using a child theme.
Child themes allow you to make changes without adding any code. Additionally, any changes you make are applied to the parent theme, allowing you to safely make updates to improve the overall customer experience.
Get fully managed WooCommerce hosting
The WooCommerce API offers many additional features that will change the way your e-commerce business operates. When used properly, it improves customer experience, improves store performance, and ultimately increases revenue.
However, a powerful tool like this API is only as good as the hosting you run it on. Nexcess is a powerful, fully managed WordPress and WooCommerce hosting. Contact our team today to find out how we can take your business and your customers’ shopping experience to the next level.