1
0
Fork 0
mirror of synced 2025-04-06 07:13:33 +03:00

Distinguishing the logic of order update with and without loyalty program

This commit is contained in:
Ivan Chaplygin 2024-06-28 10:34:39 +03:00
parent b635350606
commit 486b8f6c5e

View file

@ -125,8 +125,23 @@ if (!class_exists('WC_Retailcrm_Base')) {
add_action('woocommerce_applied_coupon', [$this, 'apply_coupon'], 11, 1);
add_action('woocommerce_review_order_before_payment', [$this, 'reviewCreditBonus'], 11, 1);
add_action('wp_trash_post', [$this, 'trash_order_action'], 10, 1);
if (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', [$this, 'take_update_order'], 11, 1);
add_action('shutdown', [$this, 'update_order_loyalty'], -1);
add_action('woocommerce_saved_order_items', [$this, 'update_order_items'], 10, 1);
}
} elseif (
!$this->get_option('deactivate_update_order')
|| $this->get_option('deactivate_update_order') == static::NO
) {
add_action('woocommerce_update_order', [$this, 'update_order'], 10, 1);
}
// Subscribed hooks
add_action('register_form', [$this, 'subscribe_register_form'], 99);
add_action('woocommerce_register_form', [$this, 'subscribe_woocommerce_register_form'], 99);
@ -139,15 +154,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, 'take_update_order'], 11, 1);
add_action('shutdown', [$this, 'update_order'], -1);
add_action('woocommerce_saved_order_items', [$this, 'update_order_items'], 10, 1);
}
if ($this->get_option('abandoned_carts_enabled') === static::YES) {
$this->cart = new WC_Retailcrm_Cart($this->apiClient, $this->settings);
@ -555,6 +561,15 @@ if (!class_exists('WC_Retailcrm_Base')) {
}
}
public function update_order($orderId)
{
if (WC_Retailcrm_Plugin::history_running() === true) {
return;
}
$this->orders->updateOrder($orderId);
}
/**
* Edit order in retailCRM
*
@ -577,7 +592,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->updatedOrderId[$order_id] = $order_id;
}
public function update_order()
public function update_order_loyalty()
{
if ($this->updatedOrderId !== []) {
foreach ($this->updatedOrderId as $orderId) {