[Store Customization] Update product slug when updating the title and flush cache (https://github.com/woocommerce/woocommerce-blocks/pull/11952)

* Check permalink and flush cache if not found

* Update the product slug with the new title

* Use wp_update_post to update the product

* Remove unused method
This commit is contained in:
Alba Rincón 2023-11-28 08:55:19 +01:00 committed by GitHub
parent 6a397d65f9
commit 175554eb97
1 changed files with 12 additions and 3 deletions

View File

@ -249,9 +249,18 @@ class ProductUpdater {
return;
}
$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'] );
wp_update_post(
array(
'ID' => $product->get_id(),
'post_title' => $ai_generated_product_content['title'],
'post_content' => $ai_generated_product_content['description'],
'post_name' => sanitize_title( $ai_generated_product_content['title'] ),
'meta_input' => array(
'_regular_price' => $ai_generated_product_content['price'],
),
)
);
flush_rewrite_rules();
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';