wc_product_has_global_unique_id()WC 9.1.0

Check if product unique ID is unique.

Возвращает

true|false.

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

wc_product_has_global_unique_id( $product_id, $global_unique_id );
$product_id(int) (обязательный)
Product ID.
$global_unique_id(строка) (обязательный)
Product Unique ID.

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

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

Код wc_product_has_global_unique_id() WC 9.4.2

function wc_product_has_global_unique_id( $product_id, $global_unique_id ) {
	/**
	 * Gives plugins an opportunity to verify Unique ID uniqueness themselves.
	 *
	 * @since 9.1.0
	 *
	 * @param bool|null $has_global_unique_id Set to a boolean value to short-circuit the default Unique ID check.
	 * @param int $product_id The ID of the current product.
	 * @param string $sku The Unique ID to check for uniqueness.
	 */
	$has_global_unique_id = apply_filters( 'wc_product_pre_has_global_unique_id', null, $product_id, $global_unique_id );
	if ( ! is_null( $has_global_unique_id ) ) {
		return boolval( $has_global_unique_id );
	}

	$data_store = WC_Data_Store::load( 'product' );
	if ( $data_store->has_callable( 'is_existing_global_unique_id' ) ) {
		$global_unique_id_found = $data_store->is_existing_global_unique_id( $product_id, $global_unique_id );
	} else {
		$logger = wc_get_logger();
		$logger->error( 'The method is_existing_global_unique_id is not implemented in the data store.', array( 'source' => 'wc_product_has_global_unique_id' ) );
	}
	/**
	 * Gives plugins an opportunity to verify Unique ID uniqueness themselves.
	 *
	 * @since 9.1.0
	 *
	 * @param boolean $global_unique_id_found Whether the Unique ID is found.
	 * @param int $product_id The ID of the current product.
	 * @param string $sku The Unique ID to check for uniqueness.
	 */
	if ( apply_filters( 'wc_product_has_global_unique_id', $global_unique_id_found, $product_id, $global_unique_id ) ) {
		return false;
	}

	return true;
}