diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php index 89693271a..8419b3e3f 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php @@ -459,6 +459,7 @@ class PayUponInvoice { if ( ! $this->pui_product_status->pui_is_active() || ! $this->pui_helper->is_checkout_ready_for_pui() + || ! $this->pui_helper->is_pay_for_order_ready_for_pui() ) { unset( $methods[ PayUponInvoiceGateway::ID ] ); } diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index bc364df72..63a721e51 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -77,6 +77,39 @@ class PayUponInvoiceHelper { return true; } + /** + * Checks whether pay for order is ready for PUI. + * + * @return bool + */ + public function is_pay_for_order_ready_for_pui(): bool { + /** + * Needed for WordPress `query_vars`. + * + * @psalm-suppress InvalidGlobal + */ + global $wp; + + $order_id = isset( $wp->query_vars['order-pay'] ) ? (int) $wp->query_vars['order-pay'] : 0; + if ( $order_id === 0 ) { + return false; + } + + $order = wc_get_order( $order_id ); + if ( ! is_a( $order, WC_Order::class ) ) { + return false; + } + + $address = $order->get_address(); + foreach ( $address as $key => $value ) { + if ( $value === '' ) { + return false; + } + } + + return true; + } + /** * Checks if currency is allowed for PUI. *