From 4ea28030f220a85a10489e92de8f3b92397ec32b Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 15 Oct 2021 13:30:34 +0200 Subject: [PATCH 1/2] Warn users of shipping rates to test for existence of meta_data correctly. As per the info in the issue itself, using `isset()` gives incorrect result all the time, so warn developers about the problem. --- plugins/woocommerce/includes/class-wc-shipping-rate.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/woocommerce/includes/class-wc-shipping-rate.php b/plugins/woocommerce/includes/class-wc-shipping-rate.php index 72bb0686d56..953d592dc6a 100644 --- a/plugins/woocommerce/includes/class-wc-shipping-rate.php +++ b/plugins/woocommerce/includes/class-wc-shipping-rate.php @@ -65,6 +65,9 @@ class WC_Shipping_Rate { * @return bool */ public function __isset( $key ) { + if ( 'meta_data' === $key ) { + wc_doing_it_wrong( __FUNCTION__, __( 'Use `array_key_exists` to check for meta_data on Shipping rates to get the correct result.', 'woocommerce' ), '6.0' ); + } return isset( $this->data[ $key ] ); } From 7a6c320fccc3ae5e82be1ee918b869773f5c9073 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 15 Oct 2021 14:06:25 +0200 Subject: [PATCH 2/2] Make the message more clear. --- plugins/woocommerce/includes/class-wc-shipping-rate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/includes/class-wc-shipping-rate.php b/plugins/woocommerce/includes/class-wc-shipping-rate.php index 953d592dc6a..f7eedbf3045 100644 --- a/plugins/woocommerce/includes/class-wc-shipping-rate.php +++ b/plugins/woocommerce/includes/class-wc-shipping-rate.php @@ -66,7 +66,7 @@ class WC_Shipping_Rate { */ public function __isset( $key ) { if ( 'meta_data' === $key ) { - wc_doing_it_wrong( __FUNCTION__, __( 'Use `array_key_exists` to check for meta_data on Shipping rates to get the correct result.', 'woocommerce' ), '6.0' ); + wc_doing_it_wrong( __FUNCTION__, __( 'Use `array_key_exists` to check for meta_data on WC_Shipping_Rate to get the correct result.', 'woocommerce' ), '6.0' ); } return isset( $this->data[ $key ] ); }