Automattic\WooCommerce\Internal\CLI\Migrator\Core

WooCommerceProductImporter::set_product_attributesprivateWC 1.0

Set product attributes.

Method of the class: WooCommerceProductImporter{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->set_product_attributes( $product, $attributes ): void;
$product(WC_Product) (required)
Product object.
$attributes(array) (required)
Attributes data.

WooCommerceProductImporter::set_product_attributes() code WC 10.7.0

private function set_product_attributes( WC_Product $product, array $attributes ): void {
	$product_attributes = array();

	foreach ( $attributes as $attribute_data ) {
		if ( empty( $attribute_data['name'] ) ) {
			continue;
		}

		$attribute = new \WC_Product_Attribute();
		$attribute->set_name( $attribute_data['name'] );
		$attribute->set_options( $attribute_data['options'] ?? array() );
		$attribute->set_variation( $attribute_data['is_variation'] ?? $attribute_data['variation'] ?? false );
		$attribute->set_visible( $attribute_data['is_visible'] ?? $attribute_data['visible'] ?? true );

		$product_attributes[] = $attribute;
	}

	$product->set_attributes( $product_attributes );
}