Automattic\WooCommerce\Blocks\Patterns

AIPatterns::update_patterns_contentpublicWC 1.0

Update the patterns content.

Method of the class: AIPatterns{}

No Hooks.

Returns

true|false|String|\WP_Error.

Usage

$AIPatterns = new AIPatterns();
$AIPatterns->update_patterns_content();

AIPatterns::update_patterns_content() code WC 9.8.5

public function update_patterns_content() {
	$allow_ai_connection = get_option( 'woocommerce_blocks_allow_ai_connection' );

	if ( ! $allow_ai_connection ) {
		return new \WP_Error(
			'ai_connection_not_allowed',
			__( 'AI content generation is not allowed on this store. Update your store settings if you wish to enable this feature.', 'woocommerce' )
		);
	}

	$ai_connection = new Connection();

	$site_id = $ai_connection->get_site_id();

	if ( is_wp_error( $site_id ) ) {
		return $site_id->get_error_message();
	}

	$token = $ai_connection->get_jwt_token( $site_id );

	if ( is_wp_error( $token ) ) {
		return $token->get_error_message();
	}

	$business_description = get_option( 'woo_ai_describe_store_description' );

	$images = ( new Pexels() )->get_images( $ai_connection, $token, $business_description );

	if ( is_wp_error( $images ) ) {
		return $images->get_error_message();
	}

	$populate_patterns = ( new UpdatePatterns() )->generate_content( $ai_connection, $token, $images, $business_description );

	if ( is_wp_error( $populate_patterns ) ) {
		return $populate_patterns->get_error_message();
	}

	$populate_products = ( new UpdateProducts() )->generate_content( $ai_connection, $token, $images, $business_description );

	if ( is_wp_error( $populate_products ) ) {
		return $populate_products->get_error_message();
	}

	return true;
}