How to add single wordpress cron event using php?
How to add single wordpress cron event using php?
add_action( 'woocommerce_thankyou', 'goaskle_auto_complete_orders' );
function goaskle_auto_complete_orders( $order_id ) {
wp_schedule_single_event(
time() + 2 * DAY_IN_SECONDS, // after 2 days
'goaskle_auto_complete_order',
array( $order_id )
);
}
add_action( 'goaskle_auto_complete_order', 'goaskle_auto_complete_order' );
function goaskle_auto_complete_order( $order_id ) {
$order = wc_get_order( $order_id );
if( ! $order ) {
return;
}
if( 'processing' === $order->get_status() ) {
$order->update_status( 'completed' );
}
}
use in wordpress php coding