[2.4] [API] Fixed editing product variations
Fixed general variations edition and make sync again variations when just edit a variable product and don't send any 'variations' data closes #9406
This commit is contained in:
parent
ddc6baf07d
commit
bfe98a283c
|
@ -399,8 +399,14 @@ class WC_API_Products extends WC_API_Resource {
|
||||||
$this->save_product_meta( $id, $data );
|
$this->save_product_meta( $id, $data );
|
||||||
|
|
||||||
// Save variations
|
// Save variations
|
||||||
if ( isset( $data['type'] ) && 'variable' == $data['type'] && isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
|
$product = get_product( $id );
|
||||||
|
if ( $product->is_type( 'variable' ) ) {
|
||||||
|
if ( isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
|
||||||
$this->save_variations( $id, $data );
|
$this->save_variations( $id, $data );
|
||||||
|
} else {
|
||||||
|
// Just sync variations
|
||||||
|
WC_Product_Variable::sync( $id );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action( 'woocommerce_api_edit_product', $id, $data );
|
do_action( 'woocommerce_api_edit_product', $id, $data );
|
||||||
|
|
|
@ -367,8 +367,14 @@ class WC_API_Products extends WC_API_Resource {
|
||||||
$this->save_product_meta( $id, $data );
|
$this->save_product_meta( $id, $data );
|
||||||
|
|
||||||
// Save variations
|
// Save variations
|
||||||
if ( isset( $data['type'] ) && 'variable' == $data['type'] && isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
|
$product = get_product( $id );
|
||||||
|
if ( $product->is_type( 'variable' ) ) {
|
||||||
|
if ( isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
|
||||||
$this->save_variations( $id, $data );
|
$this->save_variations( $id, $data );
|
||||||
|
} else {
|
||||||
|
// Just sync variations
|
||||||
|
WC_Product_Variable::sync( $id );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action( 'woocommerce_api_edit_product', $id, $data );
|
do_action( 'woocommerce_api_edit_product', $id, $data );
|
||||||
|
|
Loading…
Reference in New Issue