| @@ 1123-1141 (lines=19) @@ | ||
| 1120 | $this->save_product_shipping_data( $product_id, $data ); |
|
| 1121 | ||
| 1122 | // SKU |
|
| 1123 | if ( isset( $data['sku'] ) ) { |
|
| 1124 | $sku = get_post_meta( $product_id, '_sku', true ); |
|
| 1125 | $new_sku = wc_clean( $data['sku'] ); |
|
| 1126 | ||
| 1127 | if ( '' == $new_sku ) { |
|
| 1128 | update_post_meta( $product_id, '_sku', '' ); |
|
| 1129 | } elseif ( $new_sku !== $sku ) { |
|
| 1130 | if ( ! empty( $new_sku ) ) { |
|
| 1131 | $unique_sku = wc_product_has_unique_sku( $product_id, $new_sku ); |
|
| 1132 | if ( ! $unique_sku ) { |
|
| 1133 | throw new WC_CLI_Exception( 'woocommerce_cli_product_sku_already_exists', __( 'The SKU already exists on another product', 'woocommerce' ) ); |
|
| 1134 | } else { |
|
| 1135 | update_post_meta( $product_id, '_sku', $new_sku ); |
|
| 1136 | } |
|
| 1137 | } else { |
|
| 1138 | update_post_meta( $product_id, '_sku', '' ); |
|
| 1139 | } |
|
| 1140 | } |
|
| 1141 | } |
|
| 1142 | ||
| 1143 | // Attributes |
|
| 1144 | if ( isset( $data['attributes'] ) ) { |
|
| @@ 1573-1591 (lines=19) @@ | ||
| 1570 | } |
|
| 1571 | ||
| 1572 | // SKU |
|
| 1573 | if ( isset( $variation['sku'] ) ) { |
|
| 1574 | $sku = get_post_meta( $variation_id, '_sku', true ); |
|
| 1575 | $new_sku = wc_clean( $variation['sku'] ); |
|
| 1576 | ||
| 1577 | if ( '' == $new_sku ) { |
|
| 1578 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1579 | } elseif ( $new_sku !== $sku ) { |
|
| 1580 | if ( ! empty( $new_sku ) ) { |
|
| 1581 | $unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku ); |
|
| 1582 | if ( ! $unique_sku ) { |
|
| 1583 | throw new WC_CLI_Exception( 'woocommerce_cli_product_sku_already_exists', __( 'The SKU already exists on another product', 'woocommerce' ) ); |
|
| 1584 | } else { |
|
| 1585 | update_post_meta( $variation_id, '_sku', $new_sku ); |
|
| 1586 | } |
|
| 1587 | } else { |
|
| 1588 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1589 | } |
|
| 1590 | } |
|
| 1591 | } |
|
| 1592 | ||
| 1593 | // Thumbnail |
|
| 1594 | if ( isset( $variation['image'] ) && is_array( $variation['image'] ) ) { |
|
| @@ 1357-1375 (lines=19) @@ | ||
| 1354 | } |
|
| 1355 | ||
| 1356 | // SKU. |
|
| 1357 | if ( isset( $variation['sku'] ) ) { |
|
| 1358 | $sku = get_post_meta( $variation_id, '_sku', true ); |
|
| 1359 | $new_sku = wc_clean( $variation['sku'] ); |
|
| 1360 | ||
| 1361 | if ( '' === $new_sku ) { |
|
| 1362 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1363 | } elseif ( $new_sku !== $sku ) { |
|
| 1364 | if ( ! empty( $new_sku ) ) { |
|
| 1365 | $unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku ); |
|
| 1366 | if ( ! $unique_sku ) { |
|
| 1367 | throw new WC_REST_Exception( 'woocommerce_rest_product_sku_already_exists', __( 'The SKU already exists on another product.', 'woocommerce' ), 400 ); |
|
| 1368 | } else { |
|
| 1369 | update_post_meta( $variation_id, '_sku', $new_sku ); |
|
| 1370 | } |
|
| 1371 | } else { |
|
| 1372 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1373 | } |
|
| 1374 | } |
|
| 1375 | } |
|
| 1376 | ||
| 1377 | // Thumbnail. |
|
| 1378 | if ( isset( $variation['image'] ) && is_array( $variation['image'] ) ) { |
|