Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::is_valid_cached_order_dataprivateWC 1.0

Determine whether a cached order data record is complete and belongs to the requested order.

A valid entry is a plain stdClass whose id matches the cache key and which carries every column property that get_order_data_for_ids_from_db() populates from get_all_order_column_mappings_for_cache(). Rejecting truncated records forces a fresh database read instead of letting set_order_props_from_data() silently default the missing properties.

Method of the class: OrdersTableDataStore{}

No Hooks.

Returns

true|false. True when the record is a complete order data object for the given id.

Usage

// private - for code of main (parent) class only
$result = $this->is_valid_cached_order_data( $datum, $id ): bool;
$datum(mixed) (required)
The cached value to validate.
$id(int) (required)
The order id the entry is cached under.

OrdersTableDataStore::is_valid_cached_order_data() code WC 11.0.1

private function is_valid_cached_order_data( $datum, int $id ): bool {
	if ( ! $datum instanceof \stdClass || ! property_exists( $datum, 'id' ) || (int) $datum->id !== $id ) {
		return false;
	}

	foreach ( $this->get_all_order_column_mappings_for_cache() as $table_name => $column_mappings ) {
		foreach ( $column_mappings as $field => $map ) {
			$field_name = $map['name'] ?? "{$table_name}_$field";
			if ( ! property_exists( $datum, $field_name ) ) {
				return false;
			}
		}
	}

	return true;
}