mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Merge pull request #966 from woocommerce/PCP-739-1-9-0-test-5-pui-gateway-displayed-on-pay-for-order-page-when-mandatory-billing-fields-are-left-empty-or-country-is-unsupprted
PUI gateway displayed on pay for order page when mandatory billing fields are left empty or country is unsupprted (739)
This commit is contained in:
commit
7862f404b1
2 changed files with 46 additions and 0 deletions
|
@ -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 ] );
|
||||
}
|
||||
|
|
|
@ -132,6 +132,51 @@ 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 = (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();
|
||||
$required_fields = array(
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone',
|
||||
'address_1',
|
||||
'city',
|
||||
'postcode',
|
||||
'country',
|
||||
);
|
||||
|
||||
foreach ( $required_fields as $key ) {
|
||||
$value = $address[ $key ] ?? '';
|
||||
if ( $value === '' ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if currency is allowed for PUI.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue