WooCommerce Code Reference

UpdatePatterns
in package

Pattern Images class.

Table of Contents

WC_PATTERNS_IN_THE_ASSEMBLER  = ['woocommerce-blocks/featured-category-triple', 'woocommerce-blocks/hero-product-3-split', 'woocommerce-blocks/hero-product-chessboard', 'woocommerce-blocks/hero-product-split', 'woocommerce-blocks/product-collection-4-columns', 'woocommerce-blocks/product-collection-5-columns', 'woocommerce-blocks/social-follow-us-in-social-media', 'woocommerce-blocks/testimonials-3-columns', 'woocommerce-blocks/product-collection-featured-products-5-columns']
All patterns that are actively in use in the Assembler.
generate_ai_content_for_patterns()  : array<string|int, mixed>|WP_Error
Returns the patterns with AI generated content.
generate_content()  : bool|WP_Error
Generate AI content and assign AI-managed images to Patterns.
get_patterns_dictionary()  : mixed|WP_Error|null
Get the Patterns Dictionary.
apply_ai_responses_to_patterns()  : mixed
Applies the AI responses to the patterns.
assign_selected_images_to_patterns()  : array<string|int, mixed>|WP_Error
Assign selected images to patterns.
fetch_and_validate_ai_responses()  : array<string|int, mixed>|mixed
Fetches and validates the AI responses.
format_prompts_for_ai()  : array<string|int, mixed>
Formats the prompts for the AI.
get_images_for_pattern()  : array<string|int, mixed>
Returns the images for the given pattern.
get_selected_image_format()  : string
Returns the selected image format. Defaults to portrait.
pattern_has_images()  : bool
Returns whether the pattern has images.
prepare_expected_results_format()  : array<string|int, mixed>
Prepares the expected results format for the AI.
prepare_prompts()  : array<string|int, mixed>
Prepares the prompts for the AI.
sanitize_string()  : string
Sanitize the string from the AI generated content. It removes double quotes that can cause issues when decoding the patterns JSON.

Constants

WC_PATTERNS_IN_THE_ASSEMBLER

All patterns that are actively in use in the Assembler.

public mixed WC_PATTERNS_IN_THE_ASSEMBLER = ['woocommerce-blocks/featured-category-triple', 'woocommerce-blocks/hero-product-3-split', 'woocommerce-blocks/hero-product-chessboard', 'woocommerce-blocks/hero-product-split', 'woocommerce-blocks/product-collection-4-columns', 'woocommerce-blocks/product-collection-5-columns', 'woocommerce-blocks/social-follow-us-in-social-media', 'woocommerce-blocks/testimonials-3-columns', 'woocommerce-blocks/product-collection-featured-products-5-columns']

Methods

generate_ai_content_for_patterns()

Returns the patterns with AI generated content.

public generate_ai_content_for_patterns(Connection $ai_connection, string|WP_Error $token, array<string|int, mixed> $patterns, string $business_description) : array<string|int, mixed>|WP_Error
Parameters
$ai_connection : Connection

The AI connection.

$token : string|WP_Error

The JWT token.

$patterns : array<string|int, mixed>

The array of patterns.

$business_description : string

The business description.

Return values
array<string|int, mixed>|WP_ErrorThe patterns with AI generated content.

generate_content()

Generate AI content and assign AI-managed images to Patterns.

public generate_content(Connection $ai_connection, string|WP_Error $token, array<string|int, mixed>|WP_Error $images, string $business_description) : bool|WP_Error
Parameters
$ai_connection : Connection

The AI connection.

$token : string|WP_Error

The JWT token.

$images : array<string|int, mixed>|WP_Error

The array of images.

$business_description : string

The business description.

Return values
bool|WP_Error

get_patterns_dictionary()

Get the Patterns Dictionary.

public static get_patterns_dictionary() : mixed|WP_Error|null
Return values
mixed|WP_Error|null

apply_ai_responses_to_patterns()

Applies the AI responses to the patterns.

private apply_ai_responses_to_patterns(array<string|int, mixed> $patterns, array<string|int, mixed> $ai_responses) : mixed
Parameters
$patterns : array<string|int, mixed>

The array of patterns.

$ai_responses : array<string|int, mixed>

The array of AI responses.

Return values
mixed

assign_selected_images_to_patterns()

Assign selected images to patterns.

private assign_selected_images_to_patterns(array<string|int, mixed> $patterns_dictionary, array<string|int, mixed> $selected_images) : array<string|int, mixed>|WP_Error
Parameters
$patterns_dictionary : array<string|int, mixed>

The array of patterns.

$selected_images : array<string|int, mixed>

The array of images.

Return values
array<string|int, mixed>|WP_ErrorThe patterns with images.

fetch_and_validate_ai_responses()

Fetches and validates the AI responses.

private fetch_and_validate_ai_responses(Connection $ai_connection, string|WP_Error $token, array<string|int, mixed> $formatted_prompts, array<string|int, mixed> $expected_results_format) : array<string|int, mixed>|mixed
Parameters
$ai_connection : Connection

The AI connection.

$token : string|WP_Error

The JWT token.

$formatted_prompts : array<string|int, mixed>

The array of formatted prompts.

$expected_results_format : array<string|int, mixed>

The array of expected results format.

Return values
array<string|int, mixed>|mixed

format_prompts_for_ai()

Formats the prompts for the AI.

private format_prompts_for_ai(array<string|int, mixed> $prompts, string $business_description, array<string|int, mixed> $expected_results_format) : array<string|int, mixed>
Parameters
$prompts : array<string|int, mixed>

The array of prompts.

$business_description : string

The business description.

$expected_results_format : array<string|int, mixed>

The expected results format.

Return values
array<string|int, mixed>

get_images_for_pattern()

Returns the images for the given pattern.

private get_images_for_pattern(array<string|int, mixed> $pattern, array<string|int, mixed> $selected_images) : array<string|int, mixed>
Parameters
$pattern : array<string|int, mixed>

The array representing the pattern.

$selected_images : array<string|int, mixed>

The array of images.

Return values
array<string|int, mixed>An array containing an array of the images in the first position and their alts in the second.

get_selected_image_format()

Returns the selected image format. Defaults to portrait.

private get_selected_image_format(array<string|int, mixed> $selected_image) : string
Parameters
$selected_image : array<string|int, mixed>

The selected image to be assigned to the pattern.

Return values
stringThe selected image format.

pattern_has_images()

Returns whether the pattern has images.

private pattern_has_images(array<string|int, mixed> $pattern) : bool
Parameters
$pattern : array<string|int, mixed>

The array representing the pattern.

Return values
boolTrue if the pattern has images, false otherwise.

prepare_expected_results_format()

Prepares the expected results format for the AI.

private prepare_expected_results_format(array<string|int, mixed> $prompts) : array<string|int, mixed>
Parameters
$prompts : array<string|int, mixed>

The array of prompts.

Return values
array<string|int, mixed>

prepare_prompts()

Prepares the prompts for the AI.

private prepare_prompts(array<string|int, mixed> $patterns) : array<string|int, mixed>
Parameters
$patterns : array<string|int, mixed>

The array of patterns.

Return values
array<string|int, mixed>

sanitize_string()

Sanitize the string from the AI generated content. It removes double quotes that can cause issues when decoding the patterns JSON.

private sanitize_string(string $string) : string
Parameters
$string : string

The string to be sanitized.

Return values
stringThe sanitized string.