From 7460189752e06150500f43a7ed3fee566cecde37 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 2 Oct 2017 13:12:33 +0100 Subject: [PATCH] Handle WC_Meta_Data in get_data() and API Fixes #17003 --- includes/abstracts/abstract-wc-data.php | 9 ++++----- includes/class-wc-meta-data.php | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index ca30310dee3..8303f9d0170 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -248,13 +248,12 @@ abstract class WC_Data { * Filter null meta values from array. * * @since 3.0.0 - * - * @param mixed $meta - * + * @param mixed $meta Meta value to check. * @return bool */ protected function filter_null_meta( $meta ) { - return ! is_null( $meta->value ); + $meta = (array) $meta; + return ! is_null( $meta['value'] ); } /** @@ -265,7 +264,7 @@ abstract class WC_Data { */ public function get_meta_data() { $this->maybe_read_meta_data(); - return array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ); + return array_filter( wc_list_pluck( $this->meta_data, 'get_data' ), array( $this, 'filter_null_meta' ) ); } /** diff --git a/includes/class-wc-meta-data.php b/includes/class-wc-meta-data.php index b1830b5468b..fd8e10b3b08 100644 --- a/includes/class-wc-meta-data.php +++ b/includes/class-wc-meta-data.php @@ -101,4 +101,12 @@ class WC_Meta_Data { return $changes; } + /** + * Return all data as an array. + * + * @return array + */ + public function get_data() { + return $this->data; + } }