From bcae0166fd20a95451bef83c2e9a87d25e9323bd Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Wed, 25 Jan 2017 11:44:27 -0800 Subject: [PATCH] Fix spacing error, return objects on our new hook, and force sku to be unique when duplicating. --- includes/admin/class-wc-admin-duplicate-product.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-wc-admin-duplicate-product.php b/includes/admin/class-wc-admin-duplicate-product.php index 9a37283dd08..d27d215cbbc 100644 --- a/includes/admin/class-wc-admin-duplicate-product.php +++ b/includes/admin/class-wc-admin-duplicate-product.php @@ -98,19 +98,27 @@ class WC_Admin_Duplicate_Product { $duplicate->set_id( 0 ); $duplicate->save(); - if ( $product->is_type( 'variable' ) || $product->is_type( 'grouped' ) ) { + $sku = $duplicate->get_sku(); + if ( '' !== $duplicate->get_sku() ) { + wc_product_force_unique_sku( $duplicate->get_id() ); + } + + if ( $product->is_type( 'variable' ) || $product->is_type( 'grouped' ) ) { foreach( $product->get_children() as $child_id ) { $child = wc_get_product( $child_id ); $child_duplicate = clone $child; $child_duplicate->set_parent_id( $duplicate->get_id() ); $child_duplicate->set_id( 0 ); $child_duplicate->save(); + if ( '' !== $child_duplicate->get_sku() ) { + wc_product_force_unique_sku( $child_duplicate->get_id() ); + } } } // Hook rename to match other woocommerce_product_* hooks, and to move away from depending on a response from the wp_posts table. // New hook returns new id and old id. - do_action( 'woocommerce_product_duplicate', $duplicate->get_id(), $product_id ); + do_action( 'woocommerce_product_duplicate', $duplicate, $product ); wc_do_deprecated_action( 'woocommerce_duplicate_product', array( $duplicate->get_id(), $this->get_product_to_duplicate( $product_id ) ), '2.7', 'Use woocommerce_product_duplicate action instead.' ); // Redirect to the edit screen for the new draft page