Automattic\WooCommerce\Blocks\AIContent

UpdateProducts::update_product_content()publicWC 1.0

Update the product content with the AI-generated content.

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

Хуков нет.

Возвращает

null|WP_Error.

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

$UpdateProducts = new UpdateProducts();
$UpdateProducts->update_product_content( $ai_generated_product_content );
$ai_generated_product_content(массив) (обязательный)
The AI-generated product content.

Код UpdateProducts::update_product_content() WC 9.5.1

public function update_product_content( $ai_generated_product_content ) {
	if ( ! isset( $ai_generated_product_content['product_id'] ) ) {
		return;
	}

	$product = wc_get_product( $ai_generated_product_content['product_id'] );

	if ( ! $product instanceof \WC_Product ) {
		return;
	}

	if ( ! isset( $ai_generated_product_content['image']['src'] ) || ! isset( $ai_generated_product_content['image']['alt'] ) || ! isset( $ai_generated_product_content['title'] ) || ! isset( $ai_generated_product_content['description'] ) ) {
		return;
	}

	$product_image_id = $this->product_image_upload( $product->get_id(), $ai_generated_product_content['image']['src'], $ai_generated_product_content['image']['alt'] );

	$this->product_update( $product, $product_image_id, $ai_generated_product_content['title'], $ai_generated_product_content['description'], $ai_generated_product_content['price'] );
}