diff --git a/plugins/woocommerce-blocks/src/Patterns/ProductUpdater.php b/plugins/woocommerce-blocks/src/Patterns/ProductUpdater.php index 1cbe1556ee8..110c0d274b0 100644 --- a/plugins/woocommerce-blocks/src/Patterns/ProductUpdater.php +++ b/plugins/woocommerce-blocks/src/Patterns/ProductUpdater.php @@ -260,7 +260,6 @@ class ProductUpdater { ), ) ); - flush_rewrite_rules(); require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; diff --git a/plugins/woocommerce-blocks/src/StoreApi/Routes/V1/AI/Product.php b/plugins/woocommerce-blocks/src/StoreApi/Routes/V1/AI/Product.php index 36af63129b5..7b64b49b328 100644 --- a/plugins/woocommerce-blocks/src/StoreApi/Routes/V1/AI/Product.php +++ b/plugins/woocommerce-blocks/src/StoreApi/Routes/V1/AI/Product.php @@ -46,14 +46,14 @@ class Product extends AbstractRoute { 'callback' => [ $this, 'get_response' ], 'permission_callback' => [ Middleware::class, 'is_authorized' ], 'args' => [ - 'index' => [ - 'description' => __( 'The business description for a given store.', 'woo-gutenberg-products-block' ), - 'type' => 'integer', - ], 'products_information' => [ 'description' => __( 'Data generated by AI for updating dummy products.', 'woo-gutenberg-products-block' ), 'type' => 'object', ], + 'last_product' => [ + 'description' => __( 'Whether the product being updated is the last one in the loop', 'woo-gutenberg-products-block' ), + 'type' => 'boolean', + ], ], ], 'schema' => [ $this->schema, 'get_public_item_schema' ], @@ -82,6 +82,12 @@ class Product extends AbstractRoute { $product_updater->update_product_content( $product_information ); + $last_product_to_update = $request['last_product'] ?? false; + + if ( $last_product_to_update ) { + flush_rewrite_rules(); + } + return rest_ensure_response( array( 'ai_content_generated' => true,