Nasao sa rijesenje koje meni funckionira.
Napravio sam ove promjene u kodu:
{
add_action('woocommerce_email_order_details', [$this, 'sendApiRequestOnCheckout'], 15, 4);
add_action('woocommerce_order_status_changed', [$this, 'sendApiRequestOnOrderCompleted'], 30, 3);
}
onaj hook sam zamjenio sa ‘woocommerce_order_status_changed’ jer taj hook ima $old_status i $new_status parametre. Dok woocommerce_order_status_completed se triggera odmah, kad se napravi zahtjev za promjenom statusa u completed, ali se moze dogoditi da se sam order jos nije izmjenio (njegov status u completed), sto je kod mene problem bio.
I onda sam if provjeru samo prilagodio:
if (!is_admin() || $old_status === $new_status || $new_status !== 'completed') {
return;
}
i tu:
if ($new_status === 'completed') {...}
Definicija metode izgleda ovako sada:
public function sendApiRequestOnOrderCompleted(int $orderId, $old_status, $new_status): void
Sada sve radi normalno
-
This reply was modified 10 months, 1 week ago by crosscriss.
-
This reply was modified 10 months, 1 week ago by crosscriss.
-
This reply was modified 10 months, 1 week ago by crosscriss. Reason: code looked ugly