From c9053447adbbb4f8fba2a2b4d66dcc4f808879e9 Mon Sep 17 00:00:00 2001 From: Guilherme Pressutto Date: Wed, 15 May 2024 14:09:10 -0300 Subject: [PATCH] Fixed Afterpay for virtual products --- changelog/fix-afterpay-virtual-produts | 5 +++++ includes/class-wc-payment-gateway-wcpay.php | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-afterpay-virtual-produts diff --git a/changelog/fix-afterpay-virtual-produts b/changelog/fix-afterpay-virtual-produts new file mode 100644 index 00000000000..d2ca394a745 --- /dev/null +++ b/changelog/fix-afterpay-virtual-produts @@ -0,0 +1,5 @@ +Significance: patch +Type: fix +Comment: Fixed Afterpay for virtual products that was not released yet + + diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 8a7d1c5bc00..eddb73fa750 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -4468,8 +4468,14 @@ private function handle_afterpay_shipping_requirement( WC_Order $order, Create_A } $billing_data = $this->order_service->get_billing_data_from_order( $order ); - if ( $check_if_usable( $billing_data['address'] ) ) { - $request->set_shipping( $billing_data ); + // Afterpay fails if we send more parameters than expected in the shipping address. + // This ensures that we only send the name and address fields, as in get_shipping_data_from_order. + $shipping_data = [ + 'name' => $billing_data['name'] ?? '', + 'address' => $billing_data['address'] ?? [], + ]; + if ( $check_if_usable( $shipping_data['address'] ) ) { + $request->set_shipping( $shipping_data ); return; }