Automattic\WooCommerce\Blocks\AIContent
UpdateProducts::generate_content()
Generate AI content and assign AI-managed images to Products.
Method of the class: UpdateProducts{}
No Hooks.
Return
Array|WP_Error
. The generated content for the products. An error if the content could not be generated.
Usage
$UpdateProducts = new UpdateProducts(); $UpdateProducts->generate_content( $ai_connection, $token, $images, $business_description );
- $ai_connection(Connection) (required)
- The AI connection.
- $token(string|WP_Error) (required)
- The JWT token.
- $images(array|WP_Error) (required)
- The array of images.
- $business_description(string) (required)
- The business description.
UpdateProducts::generate_content() UpdateProducts::generate content code WC 9.8.1
public function generate_content( $ai_connection, $token, $images, $business_description ) { if ( is_wp_error( $token ) ) { return $token; } $images = ContentProcessor::verify_images( $images, $ai_connection, $token, $business_description ); if ( is_wp_error( $images ) ) { return $images; } if ( empty( $business_description ) ) { return new \WP_Error( 'missing_business_description', __( 'No business description provided for generating AI content.', 'woocommerce' ) ); } $dummy_products_to_update = $this->fetch_dummy_products_to_update(); if ( is_wp_error( $dummy_products_to_update ) ) { return $dummy_products_to_update; } if ( empty( $dummy_products_to_update ) ) { return array( 'product_content' => array(), ); } $products_information_list = $this->assign_ai_selected_images_to_dummy_products( $dummy_products_to_update, $images['images'] ); return $this->assign_ai_generated_content_to_dummy_products( $ai_connection, $token, $products_information_list, $business_description, $images['search_term'] ); }