Add filter for shipping_needed

This commit is contained in:
Kyrylo 2025-08-08 18:34:27 +03:00
parent e1e0094398
commit 68c82a831d
No known key found for this signature in database
GPG key ID: 10F523C5DD460E85

View file

@ -289,6 +289,23 @@ class PurchaseUnitFactory {
*/
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;