Automattic\WooCommerce\Internal\DataStores

CustomMetaDataStore::get_metadata_by_id()publicWC 1.0

Retrieves metadata by meta ID.

Метод класса: CustomMetaDataStore{}

Хуков нет.

Возвращает

Объект|true|false. Metadata object or FALSE if not found.

Использование

$CustomMetaDataStore = new CustomMetaDataStore();
$CustomMetaDataStore->get_metadata_by_id( $meta_id );
$meta_id(int) (обязательный)
Meta ID.

Код CustomMetaDataStore::get_metadata_by_id() WC 9.4.2

public function get_metadata_by_id( $meta_id ) {
	global $wpdb;

	if ( ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
		return false;
	}

	$db_info = $this->get_db_info();

	$meta_id = absint( $meta_id );
	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	$meta = $wpdb->get_row(
		$wpdb->prepare(
			"SELECT {$db_info['meta_id_field']}, meta_key, meta_value, {$db_info['object_id_field']} FROM {$db_info['table']} WHERE {$db_info['meta_id_field']} = %d",
			$meta_id
		)
	);
	// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

	if ( empty( $meta ) ) {
		return false;
	}

	if ( isset( $meta->meta_value ) ) {
		$meta->meta_value = maybe_unserialize( $meta->meta_value );
	}

	return $meta;
}