Automattic\WooCommerce\Internal\Utilities
COTMigrationUtil::get_post_or_object_meta()
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() COTMigrationUtil::get post or object meta WC 9.2.3
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; } }