woocommerce/docs/extension-development/woocommerce-plugin-api-call...

40 lines
975 B
Markdown
Raw Normal View History

2023-11-29 18:48:05 +00:00
---
post_title: WooCommerce plugin API callbacks
menu_title: Plugin API callbacks
tags: reference
2023-11-29 18:48:05 +00:00
---
## Overview
This document provides a guide on how to use the WooCommerce Plugin API to initiate callbacks for plugin actions, especially for gateways and classes not initialized by default.
## Callback URL Structure
Before WooCommerce 2.0, use:
`https://example.com/?wc-api=CALLBACK`
In WooCommerce 2.0 or later, use the endpoint:
`https://example.com/wc-api/CALLBACK/`
## Behavior
When the callback URL is accessed, WooCommerce will:
- Initialize the `CALLBACK` class, if available
- Trigger the `woocommerce_api_callback` action
- Exit WordPress
## Hooking into the API Callback
To hook into the callback, add an action in your plugin:
```php
add_action( 'woocommerce_api_callback', 'your_callback_handler_function' );
```
## Redirecting After Callback
It's possible to redirect users after the action has been executed using your custom handler function.