# AI Content Generator for WooCommerce

A WordPress plugin that generates product content using ChatGPT API for WooCommerce products.

## Features

### Existing Features
- **Product Image Generation**: Generate featured images and gallery images based on product details
- **Product Description Generation**: Generate detailed product descriptions with customizable tones
- **Product Short Description Generation**: Generate concise product summaries

### New Features (v1.0.3)
- **Product Brands Generation**: Generate relevant brand suggestions based on product information
- **Product Tags Generation**: Generate SEO-friendly tags and keywords for better product discoverability

## Installation

1. Upload the plugin files to `/wp-content/plugins/ai-content-generator-for-woocommerce/`
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Go to WooCommerce > AI Content Generator to configure your ChatGPT API key

## Configuration

### API Key Setup
1. Get your ChatGPT API key from [OpenAI](https://platform.openai.com/api-keys)
2. Go to WooCommerce > AI Content Generator
3. Enter your API key in the settings
4. Optionally enable debug mode for troubleshooting

## Usage

### Generating Product Content

#### Images
- **Featured Image**: Use the "Generate Featured Image" meta box on the product edit page
- **Gallery Images**: Use the "Generate Gallery Images" meta box to add multiple images

#### Descriptions
- **Main Description**: Click "Generate Description" button in the main content editor
- **Short Description**: Click "Generate Short Description" button in the excerpt editor
- **Tone Selection**: Choose from Formal, Casual, Persuasive, Technical, Luxury, or Creative tones

#### Brands and Tags
- **Brands**: Click "Generate Brands" button next to the product brands field
- **Tags**: Click "Generate Tags" button next to the product tags field
- **Selection**: Check/uncheck generated items before applying to your product

### Workflow
1. Create or edit a WooCommerce product
2. Fill in basic product information (title, categories, etc.)
3. Use the AI generation buttons to create content
4. Review and customize the generated content
5. Apply the content to your product
6. Save the product

## API Requirements

- **ChatGPT API Key**: Required for all AI generation features
- **Model**: Uses GPT-3.5-turbo for text generation and gpt-image models for image generation
- **Rate Limits**: Subject to OpenAI's API rate limits

## Debug Mode

When enabled, the plugin logs all API requests and responses to WooCommerce logs with the source 'webtoffee-ai'. This is useful for troubleshooting API issues.

## Requirements

- WordPress 6.0 or higher
- PHP 7.4 or higher
- WooCommerce plugin activated
- ChatGPT API key

## Support

For support and documentation, visit the [User Guide](user-guide-en.html) included with the plugin.

## Development

The settings screen (WooCommerce > AI Content Generator) is a React app in
`admin/modules/settings-app/app`, built with Vite and TypeScript. It takes as
much as it can from WordPress itself:

- React, from WordPress's `react` and `react-dom` scripts
- WordPress components (`wp-components`: Button, Card, TextControl,
  SelectControl, CheckboxControl, FormToggle, Modal, Notice), restyled to the
  app's look in `app/src/styles/components.css`
- `wp-i18n` for strings and `wp-api-fetch` for requests (to the plugin's
  existing admin-ajax actions)

and bundles the rest: Tailwind CSS 4 with the `wtofe:` prefix, TanStack
Router (hash routes: `#/models`, `#/chatbot` …), zustand for settings state,
react-hook-form with zod for forms, sonner for toasts and lucide-react for
icons.

Its compiled files in `admin/modules/settings-app/build` are committed, so the
plugin runs without a build step. Each comes minified (`settings-app.min.js`,
loaded by default) and readable (`settings-app.js`, loaded with
`SCRIPT_DEBUG`). Translation tools read the strings from the readable copy, so
write them as `__( 'Text', 'ai-content-generator-for-woocommerce' )` with the
domain spelled out, and translator notes as `/** translators: … */` (the build
drops other comments). WordPress loads the language pack's strings
(`wp_set_script_translations()`); PHP adds the plugin's `.mo` catalogue on top
(`WTOFE_Settings_App::get_locale_data()`).

Everything taken from WordPress is the version that WordPress release ships,
from 6.0 up, so code has to run on all of them:

- React: 17 on WordPress 6.0 and 6.1, 18 from 6.2 (18.3 as of 7.1). The build
  maps `react`, `react-dom` and the JSX runtime to `app/src/wordpress/`, so
  the app and every library in it share WordPress's copy. Keep `react` and
  `@types/react` in `package.json` at React 18 and don't use React 19 APIs.
  React 18 APIs the libraries need (`useId`, `useSyncExternalStore`,
  `startTransition` …) get React 17 stand-ins in `app/src/wordpress/react.ts`,
  and `app/src/router.tsx` batches TanStack Router's navigations on React 17.
- Components: WordPress 6.0 ships `@wordpress/components` 19.8.
  `app/src/wordpress/components.d.ts` types only the components and props that
  version has, so newer ones fail the type check. Only Button and TextControl
  pass a ref on there; the app focuses fields by id instead.
- Components given a ref need `forwardRef`; React 17 and 18 don't pass a ref
  as a prop.

After upgrading a library or changing a component, check the screen on
WordPress 6.0 (React 17) as well.

After changing anything under `app/src`, rebuild:

```bash
cd admin/modules/settings-app/app
npm install
npm run build
```

`npm run build` type-checks first (`npm run typecheck` on its own). `npm run
dev` rebuilds the readable copy on every change, with source maps; set
`SCRIPT_DEBUG` to load it. Leave `node_modules` out of release zips.

## Changelog

### v1.0.3
- Added product brands generation functionality
- Added product tags generation functionality
- Improved field detection for different WooCommerce setups
- Enhanced error handling and user feedback

### v1.0.2
- Initial release with image and description generation

## License

GPL-2.0+ 