| @@ 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 ) ) { |
|
| @@ 1323-1349 (lines=27) @@ | ||
| 1320 | $variation_post_title = sprintf( __( 'Variation #%s of %s', 'woocommerce' ), $variation_id, esc_html( get_the_title( $product->id ) ) ); |
|
| 1321 | ||
| 1322 | // Update or Add post. |
|
| 1323 | if ( ! $variation_id ) { |
|
| 1324 | $post_status = ( isset( $variation['visible'] ) && false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1325 | ||
| 1326 | $new_variation = array( |
|
| 1327 | 'post_title' => $variation_post_title, |
|
| 1328 | 'post_content' => '', |
|
| 1329 | 'post_status' => $post_status, |
|
| 1330 | 'post_author' => get_current_user_id(), |
|
| 1331 | 'post_parent' => $product->id, |
|
| 1332 | 'post_type' => 'product_variation', |
|
| 1333 | 'menu_order' => $menu_order, |
|
| 1334 | ); |
|
| 1335 | ||
| 1336 | $variation_id = wp_insert_post( $new_variation ); |
|
| 1337 | ||
| 1338 | do_action( 'woocommerce_create_product_variation', $variation_id ); |
|
| 1339 | } else { |
|
| 1340 | $update_variation = array( 'post_title' => $variation_post_title, 'menu_order' => $menu_order ); |
|
| 1341 | if ( isset( $variation['visible'] ) ) { |
|
| 1342 | $post_status = ( false === $variation['visible'] ) ? 'private' : 'publish'; |
|
| 1343 | $update_variation['post_status'] = $post_status; |
|
| 1344 | } |
|
| 1345 | ||
| 1346 | $wpdb->update( $wpdb->posts, $update_variation, array( 'ID' => $variation_id ) ); |
|
| 1347 | ||
| 1348 | do_action( 'woocommerce_update_product_variation', $variation_id ); |
|
| 1349 | } |
|
| 1350 | ||
| 1351 | // Stop with we don't have a variation ID. |
|
| 1352 | if ( is_wp_error( $variation_id ) ) { |
|