WC_Data::get_meta()
Get Meta Data by Key.
Method of the class: WC_Data{}
Hooks from the method
Return
Mixed
.
Usage
$WC_Data = new WC_Data(); $WC_Data->get_meta( $key, $single, $context );
- $key(string)
- Meta Key.
Default: '' - $single(true|false)
- return first found meta with key, or all with $key.
Default: true - $context(string)
- What the value is for. Valid values are view and edit.
Default: 'view'
Changelog
Since 2.6.0 | Introduced. |
WC_Data::get_meta() WC Data::get meta code WC 9.3.1
public function get_meta( $key = '', $single = true, $context = 'view' ) { if ( $this->is_internal_meta_key( $key ) ) { $function = 'get_' . ltrim( $key, '_' ); if ( is_callable( array( $this, $function ) ) ) { return $this->{$function}(); } } $this->maybe_read_meta_data(); $meta_data = $this->get_meta_data(); $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); $value = $single ? '' : array(); if ( ! empty( $array_keys ) ) { // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). if ( $single ) { $value = $meta_data[ current( $array_keys ) ]->value; } else { $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); } } if ( 'view' === $context ) { $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); } return $value; }