Last active
August 11, 2023 13:52
-
-
Save Awilson089/8c55203a10a3fbecc3af13bc6651220e to your computer and use it in GitHub Desktop.
Woocommerce email notification for pending order status after 10 minutes
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
add_filter( 'woocommerce_new_order_email_allows_resend', '__return_true' ); | |
add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 ); | |
function pending_new_order_notification( $order_id ) { | |
$delayTime = 600; | |
as_schedule_single_action(time() + $delayTime, 'queue_pending_email', array( $order_id ), 'customActions'); | |
} | |
add_action( 'queue_pending_email', function( $order_id ) { | |
// Thank you to @LoicTheAztec for this section of code | |
$order = wc_get_order( $order_id ); | |
// Only for "pending" order status | |
if( ! $order->has_status( 'pending' ) ) return; | |
// Get an instance of the WC_Email_New_Order object | |
$wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order']; | |
## -- Customizing Heading, subject, additional content (and optionally add recipients) -- ## | |
// Change Subject | |
$wc_email->settings['subject'] = __('{site_title} - New customer pending order ({order_number}) - {order_date}'); | |
// Change Heading | |
$wc_email->settings['heading'] = __('New Order Still Pending'); | |
// $wc_email->settings['recipient'] .= ',[email protected]'; // Add email recipients (coma separated) | |
// Change additional content | |
$wc_email->settings['additional_content'] = __('This order is currently pending.'); | |
// Send "New Email" notification (to admin) | |
$wc_email->trigger( $order_id ); | |
}, 20, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist uses action scheduler to send an email if an order is still pending after 10 minutes. Helpful for receive a notification for when an order is stuck in "Pending Payment"