Commit cd24325b81 for woocommerce

commit cd24325b81c296096202f671cd17dd3c67abe12a
Author: Ayush Pahwa <ayush.pahwa@automattic.com>
Date:   Thu Dec 4 20:27:41 2025 +0530

    [WOOPLUG-5532] fix: remove redundant data from shipping zones (#62157)

    * create: add override to remove read from shipping zone meta data table

    * create: add override to remove delete meta func

    * create: add override to remove add/update meta data

    * test: add coverage to remove meta data

    * chore: add changelog

    * update: return false for meta updates as per convention

    * update: add warnings on invalid method access

    * update: fix phpstan errors

    ---------

    Co-authored-by: Michael Pretty <prettyboymp@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/fix-wooplug-5532-shipping-zones-meta b/plugins/woocommerce/changelog/fix-wooplug-5532-shipping-zones-meta
new file mode 100644
index 0000000000..774ae118b0
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wooplug-5532-shipping-zones-meta
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Remove unnecessary data from shipping zone objects
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
index a9298a8327..78803fc370 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php
@@ -403,4 +403,84 @@ class WC_Shipping_Zone_Data_Store extends WC_Data_Store_WP implements WC_Object_
 			);
 		}
 	}
+
+	/**
+	 * Shipping zones do not support meta data.
+	 *
+	 * This override prevents the parent class from incorrectly reading from wp_postmeta,
+	 * which would happen because shipping zones use their own table but there is no
+	 * corresponding shipping zone meta table.
+	 *
+	 * @since 10.5.0
+	 * @param WC_Shipping_Zone $zone Shipping zone object.
+	 * @return array Empty array - shipping zones have no meta table.
+	 */
+	public function read_meta( &$zone ) {
+		return array();
+	}
+
+	/**
+	 * Shipping zones do not support meta data.
+	 *
+	 * @since 10.5.0
+	 * @param WC_Shipping_Zone $zone Shipping zone object.
+	 * @param stdClass         $meta Meta object (containing at least ->id).
+	 * @return array Empty array - no meta was deleted.
+	 */
+	public function delete_meta( &$zone, $meta ) {
+		wc_get_logger()->warning(
+			'Attempted to delete meta from a shipping zone, but shipping zones do not support meta data.',
+			array(
+				'source'    => 'shipping_zone_data_store',
+				'zone_id'   => $zone->get_id(),
+				'backtrace' => true,
+			)
+		);
+		return array();
+	}
+
+	/**
+	 * Shipping zones do not support meta data.
+	 *
+	 * Returns 0 to indicate no meta was added. Valid meta IDs are always positive
+	 * integers, so 0 indicates failure while remaining type-compatible with parent.
+	 *
+	 * @since 10.5.0
+	 * @param WC_Shipping_Zone $zone Shipping zone object.
+	 * @param stdClass         $meta Meta object (containing ->key and ->value).
+	 * @return int Always returns 0 as shipping zones do not support meta storage.
+	 */
+	public function add_meta( &$zone, $meta ) {
+		wc_get_logger()->warning(
+			'Attempted to add meta to a shipping zone, but shipping zones do not support meta data.',
+			array(
+				'source'    => 'shipping_zone_data_store',
+				'zone_id'   => $zone->get_id(),
+				'key'       => $meta->key ?? '',
+				'backtrace' => true,
+			)
+		);
+		return 0;
+	}
+
+	/**
+	 * Shipping zones do not support meta data.
+	 *
+	 * @since 10.5.0
+	 * @param WC_Shipping_Zone $zone Shipping zone object.
+	 * @param stdClass         $meta Meta object (containing ->id, ->key and ->value).
+	 * @return bool False - meta was not updated.
+	 */
+	public function update_meta( &$zone, $meta ) {
+		wc_get_logger()->warning(
+			'Attempted to update meta on a shipping zone, but shipping zones do not support meta data.',
+			array(
+				'source'    => 'shipping_zone_data_store',
+				'zone_id'   => $zone->get_id(),
+				'key'       => $meta->key ?? '',
+				'backtrace' => true,
+			)
+		);
+		return false;
+	}
 }
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-shipping-zone-data-store-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-shipping-zone-data-store-test.php
index cd8d1dbb6b..2fc84221bf 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-shipping-zone-data-store-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-shipping-zone-data-store-test.php
@@ -45,4 +45,75 @@ class WC_Shipping_Zone_Data_Store_CPT_Test extends WC_Unit_Test_Case {
 		$datastore = new WC_Shipping_Zone_Data_Store();
 		$datastore->read( $zone );
 	}
+
+	/**
+	 * @testdox Shipping zones do not load meta from wp_postmeta even when a post with matching ID exists.
+	 */
+	public function test_shipping_zone_does_not_load_post_meta() {
+		// Create a shipping zone.
+		$zone = new WC_Shipping_Zone();
+		$zone->set_zone_name( 'Test Zone' );
+		$zone->save();
+		$zone_id = $zone->get_id();
+
+		// Create a post with the same ID and add meta to it.
+		global $wpdb;
+		$wpdb->insert(
+			$wpdb->posts,
+			array(
+				'ID'          => $zone_id,
+				'post_type'   => 'post',
+				'post_status' => 'publish',
+				'post_title'  => 'Test Post',
+			)
+		);
+		add_post_meta( $zone_id, 'test_meta_key', 'test_meta_value' );
+
+		// Load the shipping zone fresh and verify it has no meta data.
+		$fresh_zone = new WC_Shipping_Zone( $zone_id );
+		$meta_data  = $fresh_zone->get_meta_data();
+
+		$this->assertEmpty( $meta_data, 'Shipping zone should not have loaded any meta data from wp_postmeta.' );
+
+		// Clean up.
+		wp_delete_post( $zone_id, true );
+		$zone->delete();
+	}
+
+	/**
+	 * @testdox read_meta() returns an empty array for shipping zones.
+	 */
+	public function test_read_meta_returns_empty_array() {
+		$zone = new WC_Shipping_Zone();
+		$zone->set_zone_name( 'Test Zone' );
+		$zone->save();
+
+		$datastore = new WC_Shipping_Zone_Data_Store();
+		$result    = $datastore->read_meta( $zone );
+
+		$this->assertIsArray( $result );
+		$this->assertEmpty( $result );
+
+		$zone->delete();
+	}
+
+	/**
+	 * @testdox add_meta() returns 0 as shipping zones do not support meta storage.
+	 */
+	public function test_add_meta_returns_zero() {
+		$zone = new WC_Shipping_Zone();
+		$zone->set_zone_name( 'Test Zone' );
+		$zone->save();
+
+		$datastore = new WC_Shipping_Zone_Data_Store();
+		$meta      = (object) array(
+			'key'   => 'test_key',
+			'value' => 'test_value',
+		);
+		$result    = $datastore->add_meta( $zone, $meta );
+
+		$this->assertSame( 0, $result );
+
+		$zone->delete();
+	}
 }