mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
drop shipping when only digital goods
This commit is contained in:
parent
7ae4af0886
commit
a7a74288ed
1 changed files with 19 additions and 7 deletions
|
@ -110,6 +110,7 @@ class PurchaseUnitFactory {
|
|||
$items = $this->item_factory->from_wc_order( $order );
|
||||
$shipping = $this->shipping_factory->from_wc_order( $order );
|
||||
if (
|
||||
! $this->shipping_needed( ... array_values( $items ) ) ||
|
||||
empty( $shipping->address()->country_code() ) ||
|
||||
( $shipping->address()->country_code() && ! $shipping->address()->postal_code() )
|
||||
) {
|
||||
|
@ -149,13 +150,7 @@ class PurchaseUnitFactory {
|
|||
|
||||
$shipping = null;
|
||||
$customer = \WC()->customer;
|
||||
$needs_shipping = false;
|
||||
foreach ( $items as $item) {
|
||||
if ( $item->category() !== Item::DIGITAL_GOODS ) {
|
||||
$needs_shipping = true;
|
||||
}
|
||||
}
|
||||
if ( $needs_shipping && is_a( $customer, \WC_Customer::class ) ) {
|
||||
if ( $this->shipping_needed( ... array_values( $items ) ) && is_a( $customer, \WC_Customer::class ) ) {
|
||||
$shipping = $this->shipping_factory->from_wc_customer( \WC()->customer );
|
||||
if (
|
||||
! $shipping->address()->country_code()
|
||||
|
@ -249,4 +244,21 @@ class PurchaseUnitFactory {
|
|||
);
|
||||
return $purchase_unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we need a shipping address for a set of items or not.
|
||||
*
|
||||
* @param Item ...$items The items on based which the decision is made.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shipping_needed( Item ...$items ): bool {
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
if ( $item->category() !== Item::DIGITAL_GOODS ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue