Use cron to send emails to avoid long page load times on checkout
This commit is contained in:
parent
ed51c8ac13
commit
e46b256c67
|
@ -84,17 +84,38 @@ class WC_Emails {
|
|||
) );
|
||||
|
||||
foreach ( $email_actions as $action ) {
|
||||
add_action( $action, array( __CLASS__, 'send_transactional_email' ), 10, 10 );
|
||||
add_action( $action, array( __CLASS__, 'queue_transactional_email' ), 10, 10 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue transactional email via cron so it's not sent in current request.
|
||||
*/
|
||||
public static function queue_transactional_email() {
|
||||
wp_schedule_single_event( time() + 10, 'send_queued_transactional_email', array(
|
||||
'filter' => current_filter(),
|
||||
'args' => func_get_args(),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the mailer instance and call the notifications for the current filter.
|
||||
*
|
||||
* @internal param array $args (default: array())
|
||||
*/
|
||||
public static function send_transactional_email() {
|
||||
public static function send_queued_transactional_email( $filter = '', $args = array() ) {
|
||||
self::instance(); // Init self so emails exist.
|
||||
do_action_ref_array( $filter . '_notification', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the mailer instance and call the notifications for the current filter.
|
||||
*
|
||||
* @internal param array $args (default: array())
|
||||
*/
|
||||
public static function send_transactional_email( $args = array() ) {
|
||||
$args = func_get_args();
|
||||
self::instance();
|
||||
self::instance(); // Init self so emails exist.
|
||||
do_action_ref_array( current_filter() . '_notification', $args );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue