Introduction

Writing high-quality product descriptions at scale is time-consuming — especially for stores with hundreds or thousands of SKUs. But what if you could automate it using AI?

In this guide, we’ll walk through:

  • How to integrate GPT (OpenAI) or similar LLMs into WooCommerce
  • Generating product descriptions using product attributes
  • Triggering generation on product creation/edit
  • Best practices for caching, moderation, and SEO optimization

Why Auto-Generate Product Descriptions with AI?

Benefits:

  • Scale faster: Add hundreds of products without manual writing
  • SEO-friendly: Generate keyword-optimized copy
  • Dynamic: Generate variants per language, persona, or tone
  • Custom: Tailor content to category, product type, or brand voice

Architecture Overview

We’ll build a system that:

  1. Hooks into save_post_product or uses a custom button.
  2. Sends product data (title, attributes) to OpenAI API.
  3. Receives and stores the generated content in post_content or a custom meta field.
  4. Allows optional human editing before publishing.

Requirements

  • WooCommerce installed and configured
  • OpenAI API key (get one here)
  • WordPress 6.0+ with custom admin hooks

Step-by-Step Implementation

1. Enqueue Custom Admin Script

We’ll add a button in the product editor to trigger generation.

add_action('admin_enqueue_scripts', function($hook) {
    if ($hook === 'post.php' || $hook === 'post-new.php') {
        wp_enqueue_script('product-ai-gen', plugin_dir_url(__FILE__) . 'js/product-ai.js', ['jquery'], '1.0', true);
        wp_localize_script('product-ai-gen', 'productAI', [
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce'    => wp_create_nonce('generate_description'),
        ]);
    }
});

2. Add Button to Product Editor UI

add_action('post_submitbox_misc_actions', function() {
    global $post;
    if ($post->post_type !== 'product') return;
    echo '<div class="misc-pub-section">
        <button type="button" class="button button-secondary" id="generate-description">Generate AI Description</button>
    </div>';
});

3. JavaScript Trigger (AJAX Call)

js/product-ai.js:

jQuery(document).ready(function($) {
    $('#generate-description').on('click', function() {
        const postID = $('#post_ID').val();
        $.post(productAI.ajax_url, {
            action: 'generate_product_description',
            nonce: productAI.nonce,
            post_id: postID
        }, function(response) {
            if (response.success) {
                $('#content').val(response.data).trigger('change');
                alert('AI description generated!');
            } else {
                alert('Error: ' + response.data);
            }
        });
    });
});

4. Handle AI Description Generation (Backend PHP)

add_action('wp_ajax_generate_product_description', function() {
    check_ajax_referer('generate_description', 'nonce');

    $post_id = intval($_POST['post_id']);
    $title = get_the_title($post_id);
    $attributes = wc_get_product($post_id)->get_attributes();

    $attr_string = '';
    foreach ($attributes as $attribute) {
        $attr_string .= $attribute->get_name() . ': ' . implode(', ', $attribute->get_options()) . "\n";
    }

    $prompt = "Write a compelling, SEO-optimized product description for:\n\nTitle: {$title}\nAttributes:\n{$attr_string}";

    $description = bookwp_call_openai($prompt);

    if ($description) {
        wp_send_json_success($description);
    } else {
        wp_send_json_error('Failed to generate description.');
    }
});

5. OpenAI API Call Helper Function

function bookwp_call_openai($prompt) {
    $api_key = 'your_openai_api_key';

    $response = wp_remote_post('https://api.openai.com/v1/completions', [
        'headers' => [
            'Content-Type'  => 'application/json',
            'Authorization' => 'Bearer ' . $api_key,
        ],
        'body' => json_encode([
            'model' => 'text-davinci-003',
            'prompt' => $prompt,
            'max_tokens' => 200,
            'temperature' => 0.7,
        ]),
    ]);

    if (is_wp_error($response)) return false;

    $body = json_decode(wp_remote_retrieve_body($response), true);
    return trim($body['choices'][0]['text'] ?? '');
}

Best Practices

  • Moderation: Store AI content in a custom meta field first. Let human editors review before publishing.
  • Caching: Avoid redundant API calls for the same product.
  • SEO: Use AI for inspiration but ensure uniqueness for high-value pages.
  • Limits: Respect OpenAI token rate limits and billing.

Bonus: Auto-Generate on Product Save

Optional hook:

add_action('save_post_product', function($post_id) {
    if (get_post_meta($post_id, '_ai_generated_description', true)) return;

    $description = bookwp_call_openai("Write a product description for: " . get_the_title($post_id));
    if ($description) {
        wp_update_post([
            'ID' => $post_id,
            'post_content' => $description
        ]);
        update_post_meta($post_id, '_ai_generated_description', 1);
    }
});

Conclusion

AI can drastically reduce the time it takes to write product descriptions — especially if you use structured product data like attributes or tags as input. With OpenAI or other LLMs, you can empower your WooCommerce store with scalable, intelligent content generation — all within your WordPress dashboard.