Fix filter and unit test

#11771
This commit is contained in:
Mike Jolley 2016-08-25 10:45:50 +01:00
parent 95db2f26cd
commit 543fc31d81
1 changed files with 4 additions and 5 deletions

View File

@ -107,8 +107,8 @@ abstract class WC_Data {
* Filter null meta values from array. * Filter null meta values from array.
* @return bool * @return bool
*/ */
protected function filter_null_values( $value ) { protected function filter_null_meta( $meta ) {
return ! is_null( $value ); return ! is_null( $meta->value );
} }
/** /**
@ -117,7 +117,7 @@ abstract class WC_Data {
* @return array * @return array
*/ */
public function get_meta_data() { public function get_meta_data() {
return array_filter( $this->_meta_data, array( $this, 'filter_null_values' ) ); return array_filter( $this->_meta_data, array( $this, 'filter_null_meta' ) );
} }
/** /**
@ -191,8 +191,7 @@ abstract class WC_Data {
*/ */
public function add_meta_data( $key, $value, $unique = false ) { public function add_meta_data( $key, $value, $unique = false ) {
if ( $unique ) { if ( $unique ) {
$array_keys = array_keys( wp_list_pluck( $this->_meta_data, 'key' ), $key ); $this->delete_meta_data( $key );
$this->_meta_data = array_diff_key( $this->_meta_data, array_fill_keys( $array_keys, '' ) );
} }
$this->_meta_data[] = (object) array( $this->_meta_data[] = (object) array(
'key' => $key, 'key' => $key,