WC_Product::set_sku()
Set SKU.
Method of the class: WC_Product{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WC_Product = new WC_Product(); $WC_Product->set_sku( $sku );
- $sku(string) (required)
- Product SKU.
Changelog
Since 3.0.0 | Introduced. |
WC_Product::set_sku() WC Product::set sku code WC 9.7.1
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, 'unique_sku' => wc_product_generate_unique_sku( $this->get_id(), $sku ), ) ); } $this->set_prop( 'sku', $sku ); }