1
0
Fork 0
mirror of synced 2025-04-03 22:03:34 +03:00
Added cron scheduler to update orders
This commit is contained in:
Ivan Chaplygin 2024-06-17 13:09:59 +03:00
parent d354b11ecb
commit 0d761cb902

View file

@ -105,6 +105,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
if (isLoyaltyActivate($this->settings)) {
add_action('action_update_order', [$this, 'action_update_order'], 11, 1);
add_action('wp_ajax_register_customer_loyalty', [$this, 'register_customer_loyalty']);
add_action('wp_ajax_activate_customer_loyalty', [$this, 'activate_customer_loyalty']);
add_action('init', [$this, 'add_loyalty_endpoint'], 11, 1);
@ -121,6 +122,18 @@ if (!class_exists('WC_Retailcrm_Base')) {
add_action('woocommerce_removed_coupon', [$this, 'remove_coupon'], 11, 1);
add_action('woocommerce_applied_coupon', [$this, 'apply_coupon'], 11, 1);
add_action('woocommerce_review_order_before_payment', [$this, 'reviewCreditBonus'], 11, 1);
if (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', [$this, 'update_order_loyalty'], 11, 1);
}
} elseif (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', [$this, 'update_order'], 11, 1);
}
// Subscribed hooks
@ -135,13 +148,6 @@ if (!class_exists('WC_Retailcrm_Base')) {
);
}
if (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', [$this, 'update_order'], 11, 1);
}
if ($this->get_option('abandoned_carts_enabled') === static::YES) {
$this->cart = new WC_Retailcrm_Cart($this->apiClient, $this->settings);
@ -567,6 +573,22 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->orders->updateOrder($order_id);
}
public function update_order_loyalty($order_id)
{
if (WC_Retailcrm_Plugin::history_running() === true) {
return;
}
if (!wp_next_scheduled('action_update_order', [$order_id])) {
wp_schedule_single_event(time() + 3, 'action_update_order', [$order_id] );
}
}
public function action_update_order($order_id)
{
$this->orders->updateOrder($order_id);
}
/**
* Init google analytics code
*/