After reading my Create WooCommerce order for new customers post a guy contacted me to help him create orders on his WooCommerce site for courses that are delivered by Sensei LMS. The courses are being sold via ThriveCart, a hosted shopping cart.
The guy uses Zapier as a bridge between ThriveCart and a number of other services that he uses e.g. ActiveCampaign. Via a Skype shared screen call he showed me the details of some of the zaps.
He needed a bridge to automatically create a WooCommerce order when a ThriveCart order is generated.
I browsed the ThriveCart docs and, instead of searching for a ThriveCart-WooCommerce zap, I found that ThriveCart has webhook notifications where it can pass order information to a url that you specify. The KB article gives example data.
I tried to use the WooCommerce REST API to create an order, using the provided sample code but I just could not get past the authentication. I felt that I was wasting a lot of time and not getting anywhere so I went back to the code from the post that prompted the initial contact.
I began working on a standalone script that would be called by ThriveCart. I couldn’t use my original code because it was an internal action triggered by the creation of a WooCommerce order, not by an external site. I found code on Stack Overflow to create a WooCommerce order.
I ran it alone and got it working after a few tweaks.
The next step was to get the information from an external source (mimicking the ThriveCart webhook notification). I used the demo data provided in the ThriveCart KB article. I used Postman to call the script.
The code starts by verifying that the incoming data is authentic (the ‘thrivecart_account‘ and ‘thrivecart_secret‘ and then copies the customer data into the $address array. As the ThriveCart and WooCommerce product IDs are different I added an array to map ThriveCart product IDs to their corresponding WooCommerce products.
By developing the code in incremental bits debugging it was much easier.
The project is not yet complete. The next feature will be to ensure that the WooCommerce order creates the required connection to allow access to the Sensei course.