contextResolver = $contextResolver; $this->request = $request; $this->orderRepository = $orderRepository; } /** * Gets order. * * @return Order|null */ public function getOrder(): ?Order { if ( null !== $this->order ) { return $this->order; } $orderId = $this->getOrderId(); if ( null === $orderId ) { return null; } try { $this->order = $this->orderRepository->getById( $orderId ); } catch ( InvalidCarrierException $invalidCarrierException ) { return null; } return $this->order; } /** * Gets order ID. * * @return int|null */ public function getOrderId(): ?int { global $post; if ( false === $this->contextResolver->isOrderDetailPage() ) { return null; } $idParam = $this->request->getQuery( 'id' ); if ( null !== $idParam && Module\Helper::isHposEnabled() ) { return (int) $idParam; } return $post->ID; } }