Created
August 27, 2024 23:14
-
-
Save BFTrick/26815fb3f941b2707da648fa819687ac to your computer and use it in GitHub Desktop.
Send Conversion Event via Action Scheduler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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