Prevent PHP notices while saving meta_data without an id

This commit is contained in:
Claudio Sanches 2017-02-16 01:44:45 -02:00
parent 75b2661ba3
commit 666d1f3c06
4 changed files with 4 additions and 5 deletions

View File

@ -119,7 +119,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Coupons_V1_Controller {
case 'meta_data' :
if ( is_array( $value ) ) {
foreach ( $value as $meta ) {
$coupon->update_meta_data( $meta['key'], $meta['value'], $meta['id'] );
$coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
}
}
break;

View File

@ -85,7 +85,7 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
if ( isset( $request['meta_data'] ) ) {
if ( is_array( $request['meta_data'] ) ) {
foreach ( $request['meta_data'] as $meta ) {
$customer->update_meta_data( $meta['key'], $meta['value'], $meta['id'] );
$customer->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
}
}
}

View File

@ -189,7 +189,7 @@ class WC_REST_Orders_Controller extends WC_REST_Orders_V1_Controller {
case 'meta_data' :
if ( is_array( $value ) ) {
foreach ( $value as $meta ) {
$order->update_meta_data( $meta['key'], $meta['value'], $meta['id'] );
$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
}
}
break;

View File

@ -241,8 +241,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V1_Controller {
// Allow set meta_data.
if ( is_array( $request['meta_data'] ) ) {
foreach ( $request['meta_data'] as $meta ) {
$meta_id = isset( $meta['id'] ) ? $meta['id'] : '';
$product->update_meta_data( $meta['key'], $meta['value'], $meta_id );
$product->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
}
}