From 83faf8d328ebb2d9d6e185f60d437392fd08221a Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Mon, 30 Jan 2023 13:07:05 -0800 Subject: [PATCH] Add unique sku option to error data when setting product sku (#36612) * Add unique sku option to error data when setting product sku * Add changelog entry * Add permalink template to the sku error data * Revert "Add permalink template to the sku error data" This reverts commit a49ee1d878642048b877d8eac2a1adb1829f054b. --- plugins/woocommerce/changelog/add-36589 | 4 ++++ .../includes/abstracts/abstract-wc-product.php | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 plugins/woocommerce/changelog/add-36589 diff --git a/plugins/woocommerce/changelog/add-36589 b/plugins/woocommerce/changelog/add-36589 new file mode 100644 index 00000000000..d1bd8db758d --- /dev/null +++ b/plugins/woocommerce/changelog/add-36589 @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add unique sku option to error data when setting product sku diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-product.php b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php index 3e27d48c3d6..cd9385919e5 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-product.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php @@ -820,7 +820,15 @@ class WC_Product extends WC_Abstract_Legacy_Product { if ( $this->get_object_read() && ! empty( $sku ) && ! wc_product_has_unique_sku( $this->get_id(), $sku ) ) { $sku_found = wc_get_product_id_by_sku( $sku ); - $this->error( 'product_invalid_sku', __( 'Invalid or duplicated SKU.', 'woocommerce' ), 400, array( 'resource_id' => $sku_found ) ); + $this->error( + 'product_invalid_sku', + __( 'Invalid or duplicated SKU.', 'woocommerce' ), + 400, + array( + 'resource_id' => $sku_found, + 'unique_sku' => wc_product_generate_unique_sku( $this->get_id(), $sku ), + ) + ); } $this->set_prop( 'sku', $sku ); }