wc_product_force_unique_sku()
Force a unique SKU.
No Hooks.
Return
null
. Nothing (null).
Usage
wc_product_force_unique_sku( $product_id );
- $product_id(int) (required)
- Product ID.
Changelog
Since 3.0.0 | Introduced. |
wc_product_force_unique_sku() wc product force unique sku code WC 9.2.3
function wc_product_force_unique_sku( $product_id ) { $product = wc_get_product( $product_id ); $current_sku = $product ? $product->get_sku( 'edit' ) : ''; if ( $current_sku ) { try { $new_sku = wc_product_generate_unique_sku( $product_id, $current_sku ); if ( $current_sku !== $new_sku ) { $product->set_sku( $new_sku ); $product->save(); } } catch ( Exception $e ) {} // @codingStandardsIgnoreLine. } }