Skip to content

Commit 68c82a8

Browse files
committed
Add filter for shipping_needed
1 parent e1e0094 commit 68c82a8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ function ( \stdClass $item ): Item {
289289
*/
290290
private function shipping_needed( Item ...$items ): bool {
291291

292+
/**
293+
* If you are returning false from this filter, do not forget to also set
294+
* shipping_preference to 'NO_SHIPPING', otherwise PayPal will return an error.
295+
*
296+
* @see ShippingPreferenceFactory::from_state() for
297+
* the 'woocommerce_paypal_payments_shipping_preference' filter.
298+
*/
299+
$shipping_needed = apply_filters(
300+
'woocommerce_paypal_payments_shipping_needed',
301+
null,
302+
$items
303+
);
304+
305+
if ( is_bool( $shipping_needed ) ) {
306+
return $shipping_needed;
307+
}
308+
292309
foreach ( $items as $item ) {
293310
if ( $item->category() !== Item::DIGITAL_GOODS ) {
294311
return true;

0 commit comments

Comments
 (0)