Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Store Customization > Ensure the price for products is also AI-generated #11859

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Patterns/ProductUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public function update_product_content( $ai_generated_product_content ) {

$product->set_name( $ai_generated_product_content['title'] );
$product->set_description( $ai_generated_product_content['description'] );
$product->set_regular_price( $ai_generated_product_content['price'] );

require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
Expand Down Expand Up @@ -292,6 +293,7 @@ public function assign_ai_selected_images_to_dummy_products( $dummy_products_to_
$products_information_list[] = [
'title' => 'A product title',
'description' => 'A product description',
'price' => 'The product price',
'image' => [
'src' => esc_url( $image_src ),
'alt' => esc_attr( $image_alt ),
Expand Down Expand Up @@ -329,12 +331,16 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $

$expected_results_format = [];
foreach ( $products_information_list as $index => $product ) {
$expected_results_format[ $index ] = '';
$expected_results_format[ $index ] = [
'title' => '',
'price' => '',
];
}

$formatted_prompt = sprintf(
"Generate two-words titles for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. Do not include backticks or the word json in the response. Here's an example format: '%s'.",
"Generate two-words titles and price for products using the following prompts for each one of them: '%s'. Ensure each entry is unique and does not repeat the given examples. It should be a number and it's not too low or too high for the corresponding product title being advertised. Convert the price to this currency: '%s'. Do not include backticks or the word json in the response. Here's an example format: '%s'.",
wp_json_encode( $prompts ),
get_woocommerce_currency(),
wp_json_encode( $expected_results_format )
);

Expand Down Expand Up @@ -381,7 +387,8 @@ public function assign_ai_generated_content_to_dummy_products( $ai_connection, $
}

foreach ( $products_information_list as $index => $product_information ) {
$products_information_list[ $index ]['title'] = str_replace( '"', '', $completion[ $index ] );
$products_information_list[ $index ]['title'] = str_replace( '"', '', $completion[ $index ]['title'] );
$products_information_list[ $index ]['price'] = $completion[ $index ]['price'];
}

$success = true;
Expand Down
Loading