From 44c0a34fe8b0ea2e3e67ceb07b93162c34387564 Mon Sep 17 00:00:00 2001 From: htdat Date: Sat, 22 Apr 2017 11:47:46 +0700 Subject: [PATCH] Improve calling the cron job queryDR, avoid adding the note 2 times to the order Issue: OnePay Gateway - For the type return, the $order->add_order_note() run 2 times #19 --- woo-viet.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/woo-viet.php b/woo-viet.php index 7a79b50..17d4ad4 100644 --- a/woo-viet.php +++ b/woo-viet.php @@ -145,11 +145,13 @@ class WooViet { // Add the action to check the cron job for handling queryDR // It's not possible to add in the class "WooViet_OnePay_Domestic_Hook" because it's NOT always loadded - $this->WooViet_OnePay_Domestic_Hook = new WooViet_OnePay_Domestic(); - add_action( 'wooviet_handle_onepay_querydr', array( - $this->WooViet_OnePay_Domestic_Hook, - 'handle_onepay_querydr' - ), 10, 1 ); + if ( defined( 'DOING_CRON' ) and DOING_CRON ) { + $this->WooViet_OnePay_Domestic_Hook = new WooViet_OnePay_Domestic(); + add_action( 'wooviet_handle_onepay_querydr', array( + $this->WooViet_OnePay_Domestic_Hook, + 'handle_onepay_querydr' + ), 10, 1 ); + } }