The WooCommerce API allows plugins make a callback to a special URL that will then load the specified class (if it exists) and run an action. This is also useful for gateways that are not initialized.
You can view the WC_API class in our docs.
Callback URL
To trigger the WooCommerce API, you need to use a special URL. Before WooCommerce 2.0, you could use:
http://yoursite.com/?wc-api=CALLBACK
In WooCommerce 2.0+, you can still use that or use our endpoint:
http://yoursite.com/wc-api/CALLBACK/
When this URL is called, WooCommerce:
- Initializes the CALLBACK class, if it exists
- Triggers an action based on the callback: woocommerce_api_callback. Note: CALLBACK will be sanitized and lower case.
- Exit WordPress.
Hooking into the callback
Add an action to hook into the callback hook. For example:
add_action( 'woocommerce_api_callback', 'callback_handler' );
WooCommerce will exit after that action, but you can still redirect the user elsewhere from your handler if you wish.