Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ function ( \stdClass $item ): Item {
*/
private function shipping_needed( Item ...$items ): bool {

/**
* If you are returning false from this filter, do not forget to also set
* shipping_preference to 'NO_SHIPPING', otherwise PayPal will return an error.
*
* @see ShippingPreferenceFactory::from_state() for
* the 'woocommerce_paypal_payments_shipping_preference' filter.
*/
$shipping_needed = apply_filters(
'woocommerce_paypal_payments_shipping_needed',
null,
$items
);

if ( is_bool( $shipping_needed ) ) {
return $shipping_needed;
}

foreach ( $items as $item ) {
if ( $item->category() !== Item::DIGITAL_GOODS ) {
return true;
Expand Down
23 changes: 23 additions & 0 deletions modules/ppcp-api-client/src/Factory/ShippingPreferenceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ public function from_state(
?WC_Cart $cart = null,
string $funding_source = ''
): string {
/**
* If you are using this filter to set 'NO_SHIPPING', you may also want to disable sending
* shipping fields completely.
*
* @see PurchaseUnitFactory::shipping_needed() for
* the woocommerce_paypal_payments_shipping_needed filter.
*
* @see ExperienceContext for SHIPPING_PREFERENCE_* constants.
* @see https://developer.paypal.com/serversdk/php/models/enumerations/shipping-preference/
*/
$shipping_preference = apply_filters(
'woocommerce_paypal_payments_shipping_preference',
null,
$purchase_unit,
$context,
$cart,
$funding_source
);

if ( is_string( $shipping_preference ) ) {
return $shipping_preference;
}

$contains_physical_goods = $purchase_unit->contains_physical_goods();
if ( ! $contains_physical_goods ) {
return ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING;
Expand Down
Loading