COTMigrationUtil::get_post_or_object_meta()publicWC 1.0

Gets value of a meta key from WC_Data object if passed, otherwise from the post object. This helper function support backward compatibility for meta box functions, when moving from posts based store to custom tables.

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

Хуков нет.


Массив|Разное|Строку. Value of the meta key.


$COTMigrationUtil = new COTMigrationUtil();
$COTMigrationUtil->get_post_or_object_meta( ?WP_Post $post, ?\WC_Data $data, $key, $single );
?WP_Post $post (обязательный)
?\WC_Data $data (обязательный)
$key(строка) (обязательный)
Key to fetch metadata for.
$single(true|false) (обязательный)
Whether metadata is single.

Код COTMigrationUtil::get_post_or_object_meta() WC 8.1.1

public function get_post_or_object_meta( ?WP_Post $post, ?\WC_Data $data, string $key, bool $single ) {
	if ( isset( $data ) ) {
		if ( method_exists( $data, "get$key" ) ) {
			return $data->{"get$key"}();
		return $data->get_meta( $key, $single );
	} else {
		return isset( $post->ID ) ? get_post_meta( $post->ID, $key, $single ) : false;