| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sendy\WooCommerce\Modules\Orders; |
| 4 |
|
| 5 |
use Sendy\WooCommerce\Enums\ProcessingMethod; |
| 6 |
use WC_Order; |
| 7 |
|
| 8 |
class ProcessInBackground extends OrdersModule |
| 9 |
{ |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
if (get_option('sendy_processing_method') === ProcessingMethod::Sendy) { |
| 13 |
add_action('woocommerce_checkout_order_created', [$this, 'handle_order_created']); |
| 14 |
add_action('woocommerce_order_status_changed', [$this, 'handle_order_status_change'], 10, 4); |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
public function handle_order_created(WC_Order $order): void |
| 19 |
{ |
| 20 |
if ($order->get_status() !== get_option('sendy_processable_order_status')) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
if ($order->get_meta('_sendy_shipment_id')) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
$this->create_shipment_with_smart_rules($order); |
| 29 |
} |
| 30 |
|
| 31 |
public function handle_order_status_change(int $orderId, string $oldStatus, string $newStatus, WC_Order $order): void |
| 32 |
{ |
| 33 |
if ($newStatus !== get_option('sendy_processable_order_status')) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ($order->get_meta('_sendy_shipment_id')) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
$this->create_shipment_with_smart_rules($order); |
| 42 |
} |
| 43 |
} |
| 44 |
|