WooCommerce Code Reference

UpdateProducts
in package

Pattern Images class.

Table of Contents

DUMMY_PRODUCTS  = [['title' => 'Vintage Typewriter', 'image' => 'assets/images/pattern-placeholders/writing-typing-keyboard-technology-white-vintage.jpg', 'description' => 'A hit spy novel or a love letter? Anything you type using this vintage typewriter from the 20s is bound to make a mark.', 'price' => 90], ['title' => 'Leather-Clad Leisure Chair', 'image' => 'assets/images/pattern-placeholders/table-wood-house-chair-floor-window.jpg', 'description' => 'Sit back and relax in this comfy designer chair. High-grain leather and steel frame add luxury to your your leisure.', 'price' => 249], ['title' => 'Black and White Summer Portrait', 'image' => 'assets/images/pattern-placeholders/white-black-black-and-white-photograph-monochrome-photography.jpg', 'description' => 'This 24" x 30" high-quality print just exudes summer. Hang it on the wall and forget about the world outside.', 'price' => 115], ['title' => '3-Speed Bike', 'image' => 'assets/images/pattern-placeholders/road-sport-vintage-wheel-retro-old.jpg', 'description' => 'Zoom through the streets on this premium 3-speed bike. Manufactured and assembled in Germany in the 80s.', 'price' => 115], ['title' => 'Hi-Fi Headphones', 'image' => 'assets/images/pattern-placeholders/man-person-music-black-and-white-white-photography.jpg', 'description' => 'Experience your favorite songs in a new way with these premium hi-fi headphones.', 'price' => 125], ['title' => 'Retro Glass Jug (330 ml)', 'image' => 'assets/images/pattern-placeholders/drinkware-liquid-tableware-dishware-bottle-fluid.jpg', 'description' => 'Thick glass and a classic silhouette make this jug a must-have for any retro-inspired kitchen.', 'price' => 115]]
The dummy products.
assign_ai_generated_content_to_dummy_products()  : array<string|int, mixed>|int|string|WP_Error
Generate the product content.
assign_ai_selected_images_to_dummy_products()  : array<string|int, array<string|int, mixed>>
Assigns the default content for the products.
create_hash_for_ai_modified_product()  : bool|int
Create a hash with the AI-generated content and save it as a meta for the product.
create_new_product()  : bool|int|WP_Error
Creates a new product and assigns the _headstart_post meta to it.
fetch_dummy_products_to_update()  : array<string|int, mixed>|WP_Error
Return all dummy products that were not modified by the store owner.
fetch_product_ids()  : array<string|int, mixed>|null
Return all existing products that have the _headstart_post meta assigned to them.
generate_content()  : array<string|int, mixed>|WP_Error
Generate AI content and assign AI-managed images to Products.
get_hash_for_ai_modified_product()  : false|mixed
Return the hash for a product that had its content AI-generated.
get_hash_for_product()  : false|string
Return the hash for a product based on its name, description and image_id.
reset_products_content()  : mixed
Reset the products content.
should_update_dummy_product()  : bool
Verify if the dummy product should have its content generated and managed by AI.
update_product_content()  : void|WP_Error
Update the product content with the AI-generated content.
product_image_upload()  : int|string|WP_Error
Upload the image for the product.
product_update()  : int|WP_Error
Update the product with the new content.

Constants

DUMMY_PRODUCTS

The dummy products.

public mixed DUMMY_PRODUCTS = [['title' => 'Vintage Typewriter', 'image' => 'assets/images/pattern-placeholders/writing-typing-keyboard-technology-white-vintage.jpg', 'description' => 'A hit spy novel or a love letter? Anything you type using this vintage typewriter from the 20s is bound to make a mark.', 'price' => 90], ['title' => 'Leather-Clad Leisure Chair', 'image' => 'assets/images/pattern-placeholders/table-wood-house-chair-floor-window.jpg', 'description' => 'Sit back and relax in this comfy designer chair. High-grain leather and steel frame add luxury to your your leisure.', 'price' => 249], ['title' => 'Black and White Summer Portrait', 'image' => 'assets/images/pattern-placeholders/white-black-black-and-white-photograph-monochrome-photography.jpg', 'description' => 'This 24" x 30" high-quality print just exudes summer. Hang it on the wall and forget about the world outside.', 'price' => 115], ['title' => '3-Speed Bike', 'image' => 'assets/images/pattern-placeholders/road-sport-vintage-wheel-retro-old.jpg', 'description' => 'Zoom through the streets on this premium 3-speed bike. Manufactured and assembled in Germany in the 80s.', 'price' => 115], ['title' => 'Hi-Fi Headphones', 'image' => 'assets/images/pattern-placeholders/man-person-music-black-and-white-white-photography.jpg', 'description' => 'Experience your favorite songs in a new way with these premium hi-fi headphones.', 'price' => 125], ['title' => 'Retro Glass Jug (330 ml)', 'image' => 'assets/images/pattern-placeholders/drinkware-liquid-tableware-dishware-bottle-fluid.jpg', 'description' => 'Thick glass and a classic silhouette make this jug a must-have for any retro-inspired kitchen.', 'price' => 115]]

Methods

assign_ai_generated_content_to_dummy_products()

Generate the product content.

public assign_ai_generated_content_to_dummy_products(Connection $ai_connection, string $token, array<string|int, mixed> $products_information_list, string $business_description, string $search_term) : array<string|int, mixed>|int|string|WP_Error
Parameters
$ai_connection : Connection

The AI connection.

$token : string

The JWT token.

$products_information_list : array<string|int, mixed>

The products information list.

$business_description : string

The business description.

$search_term : string

The search term.

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

assign_ai_selected_images_to_dummy_products()

Assigns the default content for the products.

public assign_ai_selected_images_to_dummy_products(array<string|int, mixed> $dummy_products_to_update, array<string|int, mixed> $ai_selected_images) : array<string|int, array<string|int, mixed>>
Parameters
$dummy_products_to_update : array<string|int, mixed>

The dummy products to update.

$ai_selected_images : array<string|int, mixed>

The images' information.

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

create_hash_for_ai_modified_product()

Create a hash with the AI-generated content and save it as a meta for the product.

public create_hash_for_ai_modified_product(WC_Product $product) : bool|int
Parameters
$product : WC_Product

The product.

Return values
bool|int

create_new_product()

Creates a new product and assigns the _headstart_post meta to it.

public create_new_product(array<string|int, mixed> $product_data) : bool|int|WP_Error
Parameters
$product_data : array<string|int, mixed>

The product data.

Return values
bool|int|WP_Error

fetch_dummy_products_to_update()

Return all dummy products that were not modified by the store owner.

public fetch_dummy_products_to_update() : array<string|int, mixed>|WP_Error
Return values
array<string|int, mixed>|WP_ErrorAn array with the dummy products that need to have their content updated by AI.

fetch_product_ids()

Return all existing products that have the _headstart_post meta assigned to them.

public fetch_product_ids([string $type = 'user_created' ]) : array<string|int, mixed>|null
Parameters
$type : string = 'user_created'

The type of products to fetch.

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

generate_content()

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

public generate_content(Connection $ai_connection, string|WP_Error $token, array<string|int, mixed>|WP_Error $images, string $business_description) : array<string|int, mixed>|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
array<string|int, mixed>|WP_ErrorThe generated content for the products. An error if the content could not be generated.

get_hash_for_ai_modified_product()

Return the hash for a product that had its content AI-generated.

public get_hash_for_ai_modified_product(WC_Product $product) : false|mixed
Parameters
$product : WC_Product

The product.

Return values
false|mixed

should_update_dummy_product()

Verify if the dummy product should have its content generated and managed by AI.

public should_update_dummy_product(WC_Product $dummy_product) : bool
Parameters
$dummy_product : WC_Product

The dummy product.

Return values
bool

update_product_content()

Update the product content with the AI-generated content.

public update_product_content(array<string|int, mixed> $ai_generated_product_content) : void|WP_Error
Parameters
$ai_generated_product_content : array<string|int, mixed>

The AI-generated product content.

Return values
void|WP_Error

product_image_upload()

Upload the image for the product.

private product_image_upload(int $product_id, string $image_src, string $image_alt) : int|string|WP_Error
Parameters
$product_id : int

The product ID.

$image_src : string

The image source.

$image_alt : string

The image alt.

Return values
int|string|WP_Error

product_update()

Update the product with the new content.

private product_update(WC_Product $product, int $product_image_id, string $product_title, string $product_description, int $product_price) : int|WP_Error
Parameters
$product : WC_Product

The product.

$product_image_id : int

The product image ID.

$product_title : string

The product title.

$product_description : string

The product description.

$product_price : int

The product price.

Return values
int|WP_Error