Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created August 27, 2024 23:14
Show Gist options
  • Save BFTrick/26815fb3f941b2707da648fa819687ac to your computer and use it in GitHub Desktop.
Save BFTrick/26815fb3f941b2707da648fa819687ac to your computer and use it in GitHub Desktop.
Send Conversion Event via Action Scheduler
<?php
/**
* Example Sending Conversion Event via Action Scheduler
*/
if ( ! function_exists( 'update_event_tracking_software' ) ) {
/**
* Handle order status changes and send events to event tracking software PAP updates.
*/
function update_event_tracking_software( $order_id, $old_status, $new_status ) {
// Schedule an API request to Event Trackig Software in the background
as_schedule_single_action( time(), 'event_tracking_change_order_status', array( $order_id, $status ) );
return;
}
}
add_action( 'woocommerce_order_status_changed', 'update_event_tracking_software', 10, 3 );
// Add actions for the Action Scheduler to run our asynchronous callback function (below)
add_action( 'event_tracking_change_order_status', 'event_tracking_change_order_status_callback', 10, 2 );
if ( ! function_exists( 'event_tracking_change_order_status_callback' ) ) {
/**
* Send conversion event to Event Tracking software
*/
function event_tracking_change_order_status_callback( $order_id, $status ) {
// Continue writing your code here.
// Action Scheduler will run this code in the background
// Send an API request.
// @see https://developer.wordpress.org/reference/functions/wp_remote_post/
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment