Merge pull request #17058 from woocommerce/fix/17047-alt

Fix meta data returns in API using JsonSerializable
This commit is contained in:
Claudio Sanches 2017-10-04 11:48:46 -03:00 committed by GitHub
commit b25e08e1cc
2 changed files with 13 additions and 5 deletions

View File

@ -252,19 +252,18 @@ abstract class WC_Data {
* @return bool
*/
protected function filter_null_meta( $meta ) {
$meta = (array) $meta;
return ! is_null( $meta['value'] );
return ! is_null( $meta->value );
}
/**
* Get All Meta Data.
*
* @since 2.6.0
* @return array
* @return array of objects.
*/
public function get_meta_data() {
$this->maybe_read_meta_data();
return array_filter( wc_list_pluck( $this->meta_data, 'get_data' ), array( $this, 'filter_null_meta' ) );
return array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) );
}
/**

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* WC_Meta_Data class.
*/
class WC_Meta_Data {
class WC_Meta_Data implements JsonSerializable {
/**
* Current data for metadata
@ -46,6 +46,15 @@ class WC_Meta_Data {
$this->apply_changes();
}
/**
* When converted to JSON.
*
* @return object
*/
public function jsonSerialize() {
return $this->get_data();
}
/**
* Merge changes with data and clear.
*/