Automattic\WooCommerce\Blocks\AIContent

UpdateProducts::assign_ai_selected_images_to_dummy_products()publicWC 1.0

Assigns the default content for the products.

Метод класса: UpdateProducts{}

Хуков нет.

Возвращает

Массив[].

Использование

$UpdateProducts = new UpdateProducts();
$UpdateProducts->assign_ai_selected_images_to_dummy_products( $dummy_products_to_update, $ai_selected_images );
$dummy_products_to_update(массив) (обязательный)
The dummy products to update.
$ai_selected_images(массив) (обязательный)
The images' information.

Код UpdateProducts::assign_ai_selected_images_to_dummy_products() WC 9.4.2

public function assign_ai_selected_images_to_dummy_products( $dummy_products_to_update, $ai_selected_images ) {
	$products_information_list = [];
	$dummy_products_count      = count( $dummy_products_to_update );
	for ( $i = 0; $i < $dummy_products_count; $i++ ) {
		$image_src = $ai_selected_images[ $i ]['URL'] ?? '';

		if ( wc_is_valid_url( $image_src ) ) {
			$image_src = ContentProcessor::adjust_image_size( $image_src, 'products' );
		}

		$image_alt = $ai_selected_images[ $i ]['title'] ?? '';

		$products_information_list[] = [
			'title'       => 'A product title',
			'description' => 'A product description',
			'price'       => 'The product price',
			'image'       => [
				'src' => $image_src,
				'alt' => $image_alt,
			],
			'product_id'  => $dummy_products_to_update[ $i ]->get_id(),
		];
	}

	return $products_information_list;
}