Webhooks were introduced in WooCommerce 2.2 and can trigger events each time you add, edit or delete orders, products, coupons or customers. fmEcommerce Link (WooCommerce Edition) supports the ‘Order Created’ Webhook – using the supplied PHP page you can have new orders automatically pushed to your copy of fmEcommerce Link.

fmEcommerce Link (WooCommerce Edition) includes PHP examples for both the FileMaker PHP API and the new Data API (support for the Data API was added in v1.65).

To use Webhooks with fmEcommerce Link you will need to ensure the following are in place:

  • your copy of fmEcommerce Link must be hosted by FileMaker Server v12 or later if you are using the PHP API Webhook files
  • your copy of fmEcommerce Link must be hosted by FileMaker Server v17 or later if you are using the Data API Webhook files
  • you will need to deploy and configure Custom Web Publishing with PHP if you are using the PHP API Webhook files
  • If you’re using the Data API Webhook files you will need to enable the Data API and host the PHP files (either on your FileMaker Server or elsewhere, for example Amazon Lightsail or your own web server)
  • you will need a static IP address/domain name for the web server that is part of the FileMaker Server deployment (we need to update the WooCommerce settings with a URL to a php page that will be hosted on your Web Server)
  • you need to install the supplied webhookNewOrder.php file on your Web Server and determine the URL to this page from the outside. For example if your web server has a domain name of www.myserver.com and you create a folder called fmecommercelink and place the webhookNewOrder.php file inside the fmecommercelink folder the URL will be: http://www.myserver.com/fmecommercelink/webhookNewOrder.php

If you’re not sure about what the external URL to the webhookNewOrder.php file is talk to your IT person – they may need to setup port forwarding on your Internet router in some cases.

The web server “root” folders for the installation location of the PHP files for FileMaker Server v13 and later is:

Windows (HTTP or HTTPS):

[drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\Conf

where [drive] is the drive on which the Web Publishing Engine component of your FileMaker server deployment resides.

Mac OS X (HTTP): 

/Library/FileMaker Server/HTTPServer/htdocs

Mac OS X (HTTPS):

/Library/FileMaker Server/HTTPServer/htdocs/httpsRoot

N.B. the HTTPS options require a valid SSL certificate to be installed.

If you are using FileMaker Server v17 or later you cannot using the FileMaker Server Admin Console to enable Custom Web Publishing using the PHP API. You will need to use the Command Line Interface to enable these – see the FileMaker Server 17 Help for more information on these commands.

The webhookNewOrder.php file calls a FileMaker script as part of the process of creating the new Order in the fmEcommerce Link file. If you are using fmEcommerce Link (WooCommerce Edition)  v1.37 or earlier you will also need to ensure that the following options are ticked in your FileMaker Server Admin Console:

server-plugins

These options can be found under the Database Server > Server Plug-Ins tab. If there are any issues with the plug-in being installed automatically by the FileMaker script you can manually install it into the following directory in your FileMaker Server installation:

\FileMaker Server\Web Publishing\publishing-engine\cwpc\Plugins

Once you have determined the URL to the webhookNewOrder.php file you need to create a Webhook within your WooCommerce  site. You can follow the WooCommerce instructions on how to setup Webhooks – make sure you select Order Created for the Topic and enter the URL to your webhookNewOrder.php file into the Delivery URL field. Once you have created and saved the Webhook it should look something like this:’

You can now create a new dummy order on your WooCommerce site and confirm that the new Order is created in the fmEcommerce Link file successfully. In our testing the new Order was created in the fmEcommerce Link file within a few seconds to a few minutes, so please wait a few minutes before troubleshooting this further.

WooCommerce keeps a log of all the Webhooks requests it makes and what the result of each request to your server was – you’ll find this under WooCommerce > Settings > API > Webhooks then click on your Webhook name:

webhook-logs

If you scroll to the right you will see the request/response details:

webhook-response

which will give you information if there was an error with the Webhook, e.g. if you don’t get 200 HTTP Status response or something other than “OK” in the <body> of the response. You might also need to consult your web server log or the FileMaker Server Log Viewer for details.

When the Webhook makes a successful request it performs the following actions:

  • it creates a new record in the Orders table and populates the WooCommerce Order ID
  • it then performs the Process Webhooks Order script and passes in the FileMaker Order ID as a parameter. This script then updates the Order record from WooCommerce – the same result if you were to manually click the Update Order from WooCommerce button

As the Order can be created before the customer has paid for the order (depending on the timing of when the Webhook is triggered) it might still have the status of ‘processing’ and not completed. You can then simply update the order from WooCommerce to get the latest version of that Order, including the payment details.

We originally had setup the Webhook to populate all the Order details using the JSON data that is sent as part of the Webhook, but we realised it wasn’t complete and missing some data compared to what is received when downloading an Order from WooCommerce via the API, so we changed it to use run the Update Current Order from WooCommerce script so it would have the same full data that the API returns.

We have a video demonstrating the Order Created Webhook in action on the fmEcommerce Link (WooCommerce Edition) Videos page.

If you would like to see support for other WooCommerce Webhooks please let us know.