Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active January 17, 2026 00:09
Show Gist options
  • Select an option

  • Save jessepearson/6ce9d0da4ace57501876434f57fdde9a to your computer and use it in GitHub Desktop.

Select an option

Save jessepearson/6ce9d0da4ace57501876434f57fdde9a to your computer and use it in GitHub Desktop.
This will turn on deferred transactional emails in WooCommerce. This may help if you are experiencing slow checkouts or checkout timeouts.
<?php // Do not copy this line
/**
* This will turn on deferred transactional emails in WooCommerce. This may help if you
* are experiencing slow checkouts or checkout timeouts.
*/
add_filter( 'woocommerce_defer_transactional_emails', '__return_true' );
@dzulhelmi
Copy link

May i know this code will defer the email to how many seconds? Minutes?

@jessepearson
Copy link
Author

@dzulhelmi it will depend on the site itself, but it shouldn't be more than a couple minutes. What this does is instead of sending emails during the checkout process, it puts them into a queue. The queue is scheduled to send in 10 seconds, but it's based on WP Cron, which depends on traffic to the site. If there's active traffic, it should only be a few seconds, but it could take a few minutes. It also depends on the hosting, if emails are slow to send on the host, it could take longer, which is why someone would use this filter in the first place.

@BenceSzalai
Copy link

It is not based on WP Cron, it uses an async queue, this one: https://github.com/deliciousbrains/wp-background-processing

What it does is basically just before PHP would shut down, it fires a remote request to the site itself without waiting for the response. The request triggers another PHP process in which the queued actions are performed. So the emails deferred this way are sent almost instantly, but they are sent in a different request, independent of the actual one, therefore any issues or waiting for SMTP server, etc cannot slow down the response to the main request.

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