Skip to content

Instantly share code, notes, and snippets.

@Awilson089
Last active August 11, 2023 13:52
Show Gist options
  • Save Awilson089/8c55203a10a3fbecc3af13bc6651220e to your computer and use it in GitHub Desktop.
Save Awilson089/8c55203a10a3fbecc3af13bc6651220e to your computer and use it in GitHub Desktop.
Woocommerce email notification for pending order status after 10 minutes
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'] .= ',name@email.com'; // 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 );
@Awilson089
Copy link
Author

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment