wc_product_has_unique_sku
Check if product sku is unique.
Description
Parameters (2)
- 0. $product_id (int)
- The product id.
- 1. $sku (string)
- The sku.
Usage
if ( !function_exists( 'wc_product_has_unique_sku' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; } // The product id. $product_id = -1; // The sku. $sku = ''; // NOTICE! Understand what this does before running. $result = wc_product_has_unique_sku($product_id, $sku);
Defined (1)
The function is defined in the following location(s).
- /includes/wc-product-functions.php
- function wc_product_has_unique_sku( $product_id, $sku ) {
- $data_store = WC_Data_Store::load( 'product' );
- $sku_found = $data_store->is_existing_sku( $product_id, $sku );
- if ( apply_filters( 'wc_product_has_unique_sku', $sku_found, $product_id, $sku ) ) {
- return false;
- } else {
- return true;
- }
- }