| @@ 1285-1311 (lines=27) @@ | ||
| 1282 | $variation_post_title = sprintf( __( 'Variation #%s of %s', 'woocommerce' ), $variation_id, esc_html( get_the_title( $product->id ) ) ); |
|
| 1283 | ||
| 1284 | // Update or Add post. |
|
| 1285 | if ( ! $variation_id ) { |
|
| 1286 | $post_status = ( isset( $variation['visible'] ) && false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1287 | ||
| 1288 | $new_variation = array( |
|
| 1289 | 'post_title' => $variation_post_title, |
|
| 1290 | 'post_content' => '', |
|
| 1291 | 'post_status' => $post_status, |
|
| 1292 | 'post_author' => get_current_user_id(), |
|
| 1293 | 'post_parent' => $product->id, |
|
| 1294 | 'post_type' => 'product_variation', |
|
| 1295 | 'menu_order' => $menu_order, |
|
| 1296 | ); |
|
| 1297 | ||
| 1298 | $variation_id = wp_insert_post( $new_variation ); |
|
| 1299 | ||
| 1300 | do_action( 'woocommerce_create_product_variation', $variation_id ); |
|
| 1301 | } else { |
|
| 1302 | $update_variation = array( 'post_title' => $variation_post_title, 'menu_order' => $menu_order ); |
|
| 1303 | if ( isset( $variation['visible'] ) ) { |
|
| 1304 | $post_status = ( false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1305 | $update_variation['post_status'] = $post_status; |
|
| 1306 | } |
|
| 1307 | ||
| 1308 | $wpdb->update( $wpdb->posts, $update_variation, array( 'ID' => $variation_id ) ); |
|
| 1309 | ||
| 1310 | do_action( 'woocommerce_update_product_variation', $variation_id ); |
|
| 1311 | } |
|
| 1312 | ||
| 1313 | // Stop with we don't have a variation ID. |
|
| 1314 | if ( is_wp_error( $variation_id ) ) { |
|
| @@ 1539-1565 (lines=27) @@ | ||
| 1536 | $variation_post_title = sprintf( __( 'Variation #%s of %s', 'woocommerce' ), $variation_id, esc_html( get_the_title( $id ) ) ); |
|
| 1537 | ||
| 1538 | // Update or Add post |
|
| 1539 | if ( ! $variation_id ) { |
|
| 1540 | $post_status = ( isset( $variation['visible'] ) && false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1541 | ||
| 1542 | $new_variation = array( |
|
| 1543 | 'post_title' => $variation_post_title, |
|
| 1544 | 'post_content' => '', |
|
| 1545 | 'post_status' => $post_status, |
|
| 1546 | 'post_author' => get_current_user_id(), |
|
| 1547 | 'post_parent' => $id, |
|
| 1548 | 'post_type' => 'product_variation', |
|
| 1549 | 'menu_order' => $menu_order |
|
| 1550 | ); |
|
| 1551 | ||
| 1552 | $variation_id = wp_insert_post( $new_variation ); |
|
| 1553 | ||
| 1554 | do_action( 'woocommerce_create_product_variation', $variation_id ); |
|
| 1555 | } else { |
|
| 1556 | $update_variation = array( 'post_title' => $variation_post_title, 'menu_order' => $menu_order ); |
|
| 1557 | if ( isset( $variation['visible'] ) ) { |
|
| 1558 | $post_status = ( false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1559 | $update_variation['post_status'] = $post_status; |
|
| 1560 | } |
|
| 1561 | ||
| 1562 | $wpdb->update( $wpdb->posts, $update_variation, array( 'ID' => $variation_id ) ); |
|
| 1563 | ||
| 1564 | do_action( 'woocommerce_update_product_variation', $variation_id ); |
|
| 1565 | } |
|
| 1566 | ||
| 1567 | // Stop with we don't have a variation ID |
|
| 1568 | if ( is_wp_error( $variation_id ) ) { |
|