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.

{} It's a method of the class: COTMigrationUtil{}

No Hooks.


Array|Mixed|String. 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 (required)
?\WC_Data $data (required)
$key(string) (required)
Key to fetch metadata for.
$single(true|false) (required)
Whether metadata is single.

Code of COTMigrationUtil::get_post_or_object_meta() WC 7.1.0

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 get_post_meta( $post->ID, $key, $single );