WordPress at Your Fingertips
function is not described

WC_Product::set_sku() public WC 3.0.0

Set SKU.

{} It's a method of the class: WC_Product{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Product = new WC_Product();
$WC_Product->set_sku( $sku );
$sku(string) (required)
Product SKU.

Changelog

Since 3.0.0 Introduced.

Code of WC_Product::set_sku() WC 5.8.0

public function set_sku( $sku ) {
	$sku = (string) $sku;
	if ( $this->get_object_read() && ! empty( $sku ) && ! wc_product_has_unique_sku( $this->get_id(), $sku ) ) {
		$sku_found = wc_get_product_id_by_sku( $sku );

		$this->error( 'product_invalid_sku', __( 'Invalid or duplicated SKU.', 'woocommerce' ), 400, array( 'resource_id' => $sku_found ) );
	}
	$this->set_prop( 'sku', $sku );
}