metaboxesWrapper = $metaboxesWrapper; $this->orderRepository = $orderRepository; } /** * Registers hooks. * * @return void */ public function register(): void { add_action( 'woocommerce_update_order', [ $this, 'updateOrder' ] ); } /** * Runs multiple scripts when the WC function is triggered. * * @param int|mixed $wcOrderId Order ID. * * @return void */ public function updateOrder( $wcOrderId ): void { static $hasBeenRun; if ( isset( $hasBeenRun ) && $hasBeenRun === true ) { return; } $wcOrder = $this->orderRepository->getWcOrderById( (int) $wcOrderId ); if ( $wcOrder === null ) { return; } if ( ! ShippingProvider::wcOrderHasOurMethod( $wcOrder ) ) { $this->orderRepository->delete( (int) $wcOrderId ); $hasBeenRun = true; return; } $this->metaboxesWrapper->saveFields( $wcOrderId ); $hasBeenRun = true; } }