FunnelKit
FunnelKit Documentation
Get unstuck with our helpful reference material

FunnelKit Automations

Use Custom Callback action

'Custom Callback' action is used to execute a PHP code.

To select custom callback, go to WordPress > Custom Callback option under actions.

This is how the 'Custom Callback' action UI looks.

Enter custom callback name

Note: Every event has its own data, which is passed to the custom callback.

Here's a Custom Callback in action on the 'WooCommerce Subscription: Subscriptions Before Renewal' event:


/**
* Callback from FunnelKit Automations
* Event: WooCommerce Subscription: Subscriptions Before Renewal
* Cancelling subscription if parent order is refunded or cancelled
* http://imgwxl.com/a/screenshot-17-06-25.png
*/
add_action( 'bwf_subscription_order_status_check', 'bwf_subscription_order_status_check_func' );

/**
* $args Array
* Contains all the possible data from the FunnelKit Automations triggered event
*/
function bwf_subscription_order_status_check_func( $args ) {
$subscription_id = isset( $args['wc_subscription_id'] ) && ! empty( $args['wc_subscription_id'] ) ? $args['wc_subscription_id'] : false;
if ( false === $subscription_id || empty( $subscription_id ) ) {
return;
}
$subscription = wcs_get_subscription( $subscription_id );
$order_statuses = array( 'refunded', 'cancelled' );
$subscription_order = $subscription->get_parent();

if ( $subscription_order instanceof WC_Order && ! in_array( $subscription_order->get_status(), $order_statuses, true ) ) {
return;
}

try {
$subscription->update_status( 'cancelled' );
} catch ( Exception $e ) {
return;
}

}

Note: Add the add_action line to hook your callback, then write the callback function itself.

Here's another Custom Callback in action on the 'WooCommerce: Order Created' event:

/**
 * Callback from FunnelKit Automations
 * Event: WooCommerce: Order Created
 */
add_action( 'bwf_order_created_event_callback', 'bwf_order_created_event_callback_func' );

function bwf_order_created_event_callback_func( $args ) {

	/**
	 * Data
	 *
	 * $args[order_id] - Order ID
	 * $args[email] - Order Billing Email
	 * $args[phone] - Order Billing Phone (if available)
	 * $args[automation_id] - Automation ID
	 */

	try {
		/**
		 * Execute code here
		 */
	} catch ( Exception $e ) {
		return;
	}

}

This is how you can use a custom callback within Automations.

Ready to Transform Your Store?
Join 39,415+ successful store owners who trust FunnelKit to power their businesses.
Conversion Optimized Checkout Pages
Increase Revenue with Smart Upsells
Capture Emails & Recover Abandoned Carts
Automate Winbacks & Repeat Sales
973+ 5 star reviews on WordPress.org
Transform your store to power your business with FunnelKit
🚀 Maximize Your Profit with FunnelKit – Highest Rated with 973+ 5-Star Reviews
Get Started