File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
modules/ppcp-api-client/src/Factory Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,23 @@ function ( \stdClass $item ): Item {
292292 */
293293 private function shipping_needed ( Item ...$ items ): bool {
294294
295+ /**
296+ * If you are returning false from this filter, do not forget to also set
297+ * shipping_preference to 'NO_SHIPPING', otherwise PayPal will return an error.
298+ *
299+ * @see ShippingPreferenceFactory::from_state() for
300+ * the 'woocommerce_paypal_payments_shipping_preference' filter.
301+ */
302+ $ shipping_needed = apply_filters (
303+ 'woocommerce_paypal_payments_shipping_needed ' ,
304+ null ,
305+ $ items
306+ );
307+
308+ if ( is_bool ( $ shipping_needed ) ) {
309+ return $ shipping_needed ;
310+ }
311+
295312 foreach ( $ items as $ item ) {
296313 if ( $ item ->category () !== Item::DIGITAL_GOODS ) {
297314 return true ;
Original file line number Diff line number Diff line change @@ -37,6 +37,29 @@ public function from_state(
3737 string $ funding_source = '' ,
3838 ?WC_Order $ wc_order = null
3939 ): string {
40+ /**
41+ * If you are using this filter to set 'NO_SHIPPING', you may also want to disable sending
42+ * shipping fields completely.
43+ *
44+ * @see PurchaseUnitFactory::shipping_needed() for
45+ * the woocommerce_paypal_payments_shipping_needed filter.
46+ *
47+ * @see ExperienceContext for SHIPPING_PREFERENCE_* constants.
48+ * @see https://developer.paypal.com/serversdk/php/models/enumerations/shipping-preference/
49+ */
50+ $ shipping_preference = apply_filters (
51+ 'woocommerce_paypal_payments_shipping_preference ' ,
52+ null ,
53+ $ purchase_unit ,
54+ $ context ,
55+ $ cart ,
56+ $ funding_source
57+ );
58+
59+ if ( is_string ( $ shipping_preference ) ) {
60+ return $ shipping_preference ;
61+ }
62+
4063 $ contains_physical_goods = $ purchase_unit ->contains_physical_goods ();
4164 if ( ! $ contains_physical_goods ) {
4265 return ExperienceContext::SHIPPING_PREFERENCE_NO_SHIPPING ;
You can’t perform that action at this time.
0 commit comments