| @@ 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'] ) ) { |
|
| @@ 1319-1337 (lines=19) @@ | ||
| 1316 | } |
|
| 1317 | ||
| 1318 | // SKU. |
|
| 1319 | if ( isset( $variation['sku'] ) ) { |
|
| 1320 | $sku = get_post_meta( $variation_id, '_sku', true ); |
|
| 1321 | $new_sku = wc_clean( $variation['sku'] ); |
|
| 1322 | ||
| 1323 | if ( '' === $new_sku ) { |
|
| 1324 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1325 | } elseif ( $new_sku !== $sku ) { |
|
| 1326 | if ( ! empty( $new_sku ) ) { |
|
| 1327 | $unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku ); |
|
| 1328 | if ( ! $unique_sku ) { |
|
| 1329 | throw new WC_REST_Exception( 'woocommerce_rest_product_sku_already_exists', __( 'The SKU already exists on another product.', 'woocommerce' ), 400 ); |
|
| 1330 | } else { |
|
| 1331 | update_post_meta( $variation_id, '_sku', $new_sku ); |
|
| 1332 | } |
|
| 1333 | } else { |
|
| 1334 | update_post_meta( $variation_id, '_sku', '' ); |
|
| 1335 | } |
|
| 1336 | } |
|
| 1337 | } |
|
| 1338 | ||
| 1339 | // Thumbnail. |
|
| 1340 | if ( isset( $variation['image'] ) && is_array( $variation['image'] ) ) { |
|