Allow save meta data for products in v2
This commit is contained in:
parent
d2818be2ba
commit
036a2f6c92
|
@ -227,6 +227,28 @@ class WC_REST_Products_Controller extends WC_REST_Products_V1_Controller {
|
|||
return $variations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product meta.
|
||||
*
|
||||
* @throws WC_REST_Exception REST API exceptions.
|
||||
* @param WC_Product $product Product instance.
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WC_Product
|
||||
*/
|
||||
protected function set_product_meta( $product, $request ) {
|
||||
$product = parent::set_product_meta( $product, $request );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Product's schema, conforming to JSON Schema.
|
||||
*
|
||||
|
|
|
@ -1063,7 +1063,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
* @throws WC_REST_Exception
|
||||
*/
|
||||
protected function save_product_meta( $product, $request ) {
|
||||
$this->set_product_meta( $product, $request );
|
||||
$product = $this->set_product_meta( $product, $request );
|
||||
$product->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1353,8 +1354,6 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
$product = $this->save_default_attributes( $product, $request );
|
||||
}
|
||||
|
||||
$product->save();
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue