wc_product_has_unique_sku filter-hookWC 10.5.0

Gives plugins an opportunity to verify SKU uniqueness themselves. Filter added to keep backwards compatibility with wc_product_has_unique_sku(). See: https://github.com/woocommerce/woocommerce/pull/62628

Usage

add_filter( 'wc_product_has_unique_sku', 'wp_kama_wc_product_has_unique_sku_filter', 10, 3 );

/**
 * Function for `wc_product_has_unique_sku` filter-hook.
 * 
 * @param bool|null $sku_found  Set to a boolean value to short-circuit the default SKU check.
 * @param int       $product_id The ID of the current product.
 * @param string    $sku        The SKU to check for uniqueness.
 *
 * @return bool|null
 */
function wp_kama_wc_product_has_unique_sku_filter( $sku_found, $product_id, $sku ){

	// filter...
	return $sku_found;
}
$sku_found(true|false|null)
Set to a boolean value to short-circuit the default SKU check.
$product_id(int)
The ID of the current product.
$sku(string)
The SKU to check for uniqueness.

Changelog

Since 10.5.0 Introduced.

Where the hook is called

WC_Admin_Duplicate_Product::generate_unique_sku()
wc_product_has_unique_sku
wc_product_has_unique_sku()
wc_product_has_unique_sku
woocommerce/includes/admin/class-wc-admin-duplicate-product.php 391
$sku_found = apply_filters( 'wc_product_has_unique_sku', false, $product_id, $new_sku );
woocommerce/includes/wc-product-functions.php 987
if ( apply_filters( 'wc_product_has_unique_sku', $sku_found, $product_id, $sku ) ) {

Where the hook is used in WooCommerce

woocommerce/src/Internal/CLI/Migrator/Core/WooCommerceProductImporter.php 534
add_filter( 'wc_product_has_unique_sku', '__return_false', 999 );
woocommerce/src/Internal/CLI/Migrator/Core/WooCommerceProductImporter.php 536
remove_filter( 'wc_product_has_unique_sku', '__return_false', 999 );
woocommerce/src/Internal/CLI/Migrator/Core/WooCommerceProductImporter.php 801
add_filter( 'wc_product_has_unique_sku', '__return_false', 999 );
woocommerce/src/Internal/CLI/Migrator/Core/WooCommerceProductImporter.php 803
remove_filter( 'wc_product_has_unique_sku', '__return_false', 999 );