Created
March 30, 2020 13:46
-
-
Save damiencarbery/b2d0889364a0fd6878024402e1697104 to your computer and use it in GitHub Desktop.
Defer Order Complete emails - Defer Order Complete emails for 10 minutes. DOES NOT WORK.
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
<?php | |
/* | |
Plugin Name: Defer Order Complete emails | |
Plugin URI: https://www.damiencarbery.com/ | |
Description: Defer Order Complete emails for a few minutes. | |
Author: Damien Carbery | |
Author URI: https://www.damiencarbery.com | |
Version: 0.1 | |
*/ | |
add_filter( 'woocommerce_allow_send_queued_transactional_email', 'dcwd_whether_send_queued_wc_email', 10, 3 ); | |
function dcwd_whether_send_queued_wc_email( $true, $filter, $args ) { | |
error_log( 'woocommerce_allow_send_queued_transactional_email $filter: ' . var_export( $filter, true ) ); | |
error_log( 'woocommerce_allow_send_queued_transactional_email order_number: ' . var_export( $args[ 0 ], true ) ); | |
//error_log( 'woocommerce_allow_send_queued_transactional_email $args: ' . var_export( $args, true ) ); | |
if ( 'woocommerce_order_status_completed' == $filter ) { | |
// TODO: Limit checks to this email. | |
} | |
$order = wc_get_order( $args[ 0 ] ); | |
$now = strtotime( current_time( 'mysql' ) ); | |
$order_modified = strtotime( $order->get_date_modified() ); | |
error_log( "woocommerce_allow_send_queued_transactional_email now/order modified: ".current_time( 'mysql' )."/".$order->get_date_modified() ); | |
if ( ( $now - $order_modified ) < 600 ) { | |
error_log( 'woocommerce_allow_send_queued_transactional_email: Less than 600 sec so do not send email.' ); | |
return false; | |
} | |
//error_log( 'woocommerce_allow_send_queued_transactional_email modified: ' . var_export( $order->get_date_modified(), true ) ); | |
//error_log( 'woocommerce_allow_send_queued_transactional_email now: ' . var_export( time(), true ) ); | |
error_log( 'woocommerce_allow_send_queued_transactional_email: Ok to send email.' ); | |
return $true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment