wc_product_has_unique_sku хук-фильтрWC 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

Использование

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(строка)
The SKU to check for uniqueness.

Список изменений

С версии 10.5.0 Введена.

Где вызывается хук

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 1029
if ( apply_filters( 'wc_product_has_unique_sku', $sku_found, $product_id, $sku ) ) {

Где используется хук в 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 );