WC_API – The WooCommerce API Callback

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 ↑ Back to top

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:

  1. Initializes the CALLBACK class, if it exists
  2. Triggers an action based on the callback: woocommerce_api_callback. Note: CALLBACK will be sanitized and lower case.
  3. Exit WordPress.

Hooking into the callback ↑ Back to top

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.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top