WordPress at Your Fingertips
function is not described

wc_product_generate_unique_sku() WC 3.0.0

Recursively appends a suffix until a unique SKU is found.

No Hooks.

Return

String.

Usage

wc_product_generate_unique_sku( $product_id, $sku, $index );
$product_id(int) (required)
Product ID.
$sku(string) (required)
Product SKU.
$index(int)
An optional index that can be added to the product SKU.

Changelog

Since 3.0.0 Introduced.

Code of wc_product_generate_unique_sku() WC 5.5.2

<?php
function wc_product_generate_unique_sku( $product_id, $sku, $index = 0 ) {
	$generated_sku = 0 < $index ? $sku . '-' . $index : $sku;

	if ( ! wc_product_has_unique_sku( $product_id, $generated_sku ) ) {
		$generated_sku = wc_product_generate_unique_sku( $product_id, $sku, ( $index + 1 ) );
	}

	return $generated_sku;
}