Inter-connectedness of all things is the way of the future–including in online commerce. Understanding this, WooCommerce comes with two primary tools to achieve this: the REST APIWhere WooCommerce replies to requests from external sources and WebhooksWhere WooCommerce “announces” data to an external source. In this course we’ll cover:
If you prefer, you can jump to the Knowledge check to see what you already know
From the Docs: On the left is a simple example of a GET request (by post_id) of a product. On the right is a POST request to create a product
REST API Keys are stored in the woocommerce_api_keysAll table names are give without $wpdb->prefix (naturally) table
…but life can get even easier if you’ll let it. WooCommerce API libraries have been specifically designed for connecting to stores in the following languages:
The act of creating a Webhooks is devilishly simple. Rather than re-invent the wheel, I’ll refer you to the information in the docs, as it is straightforward and complete.
Webhooks are directly linked with the WordPress REST API in that they build their payload using the REST API and specified version.
private function get_wp_api_payload( $resource, $resource_id, $event ) {
switch ( $resource ) {
case 'coupon':
case 'customer':
case 'order':
case 'product':
// Bulk and quick edit action hooks return a product object instead of an ID.
if ( 'product' === $resource && 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) {
$resource_id = $resource_id->get_id();
}
$version = str_replace( 'wp_api_', '', $this->get_api_version() );
$payload = wc()->api->get_endpoint_data( "/wc/{$version}/{$resource}s/{$resource_id}" );
break;
Stored in the wc_webhook tableOf course, you could change the way the data is save, by implementing a custom data store, if necessary
Now that you’ve gotten the ‘lay of the land’ on Webhooks and the REST API. I imagine there’s one thing weighing on your mind…
In the next topic, we’ll take a look at how the APIs are configured to keep those cats out of your store…
But first, check your knowledge.
Hint: You can look at the slides in the topic at any time, while you work on the questions 😉 Using the left arrow button will take you back to the topic content
0 of 3 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 3 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Which of the following is NOT a field in the woocommerce_api_keys table?
Which of the following is NOT stored in the wc_webhook table?
Client libraries for the WooCommerce REST API are available in which languages?