Integrate OpenAI API with WooCommerce to Auto Generate Product Data

Integrate OpenAI API with WooCommerce to Auto Generate Product Data

14 minutes read

May 05, 2026

Integrate OpenAI API with WooCommerce to Auto Generate Product Data

The Challenge of Scaling Product Content in WooCommerce

Running a WooCommerce store involves a lot more than just adding products and processing orders. One of the most time-consuming aspects of managing an e-commerce store is creating high-quality product data. This includes product titles, descriptions, short descriptions, meta tags, attributes and even SEO content. 

Manually writing this content for hundreds or thousands of products can quickly become overwhelming. This is where the OpenAI API comes in. By integrating OpenAI with WooCommerce, you can automate product content generation, improve consistency and save countless hours of manual effort. 

In this blog, we will walk through how to integrate the OpenAI API with WooCommerce to automatically generate product data. We will also explore practical implementation steps, code examples and best practices. 

Why Use OpenAI with WooCommerce? 

Before diving into implementation, let’s understand why this integration is valuable. 

  1. Save Time

Generating product descriptions manually is repetitive and time-consuming. OpenAI can create content in seconds. 

  1. Improve SEO

AI-generated content can be optimized with keywords, improving search engine visibility. 

  1. Maintain Consistency

AI ensures consistent tone, structure and formatting across all product listings. 

  1. Scale Easily

Whether you have 50 or 50,000 products, AI can handle large-scale content generation effortlessly.

What You Can Automate 

Using OpenAI, you can automatically generate: 

  • Product titles 
  • Long descriptions 
  • Short descriptions 
  • SEO meta descriptions 
  • Product features & bullet points 
  • Tags and categories 
  • FAQs for products

Prerequisites 

Before starting, make sure you have: 

  • A WordPress website with WooCommerce installed 
  • Basic knowledge of PHP and WordPress hooks 
  • OpenAI API key 
  • Access to your theme’s functions.php file or a custom plugin

Step 1: Get OpenAI API Key 

  1. Go to OpenAI’s official platform 
  2. Sign in or create an account 
  3. Generate your API key 

Store this key securely. You will use it in your code. 

Step 2: Create a Custom Plugin (Recommended) 

Instead of modifying your theme directly, create a custom plugin. 

Create Plugin File 

Create a file: 


wp-content/plugins/woo-openai-generator/woo-openai-generator.php 

Add Basic Plugin Header


<?php
/* 
Plugin Name: WooCommerce OpenAI Product Generator 
Description: Auto generate WooCommerce product content using OpenAI API. 
Version: 1.0 
Author: Your Name 
*/  

Step 3: Connect to OpenAI API 

Add a function to send requests to OpenAI. 

function generate_openai_content($prompt) { 
	$api_key = 'YOUR_OPENAI_API_KEY'; 
 
	$response = wp_remote_post('https://api.openai.com/v1/chat/completions', [ 
    	'headers' => [ 
        	'Content-Type'  => 'application/json', 
        	'Authorization' => 'Bearer ' . $api_key, 
    	], 
    	'body' => json_encode([ 
        	'model' => 'gpt-4o-mini', 
        	'messages' => [ 
            	[ 
                	'role' => 'user', 
                	'content' => $prompt 
            	] 
        	], 
        	'temperature' => 0.7 
    	]) 
	]); 
 
	if (is_wp_error($response)) { 
    	return ''; 
	} 
 
	$body = json_decode(wp_remote_retrieve_body($response), true); 
	return $body['choices'][0]['message']['content'] ?? ''; 
} 

Step 4: Generate Product Description Automatically 

Hook into WooCommerce product save action. 

add_action('save_post_product', 'auto_generate_product_content', 20, 3); 
 
function auto_generate_product_content($post_id, $post, $update) { 
 
	if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) { 
    	return; 
	} 
 
	// Avoid overwriting existing content 
	if (!empty($post->post_content)) { 
    	return; 
	} 
 
	$product_title = get_the_title($post_id); 
 
	$prompt = "Write a professional WooCommerce product description for: {$product_title}. Include features, benefits and a persuasive tone."; 
 
	$generated_content = generate_openai_content($prompt); 
 
	if (!empty($generated_content)) { 
    	wp_update_post([ 
        	'ID' => $post_id, 
        	'post_content' => $generated_content 
    	]); 
	} 
} 

Step 5: Generate Short Description 

WooCommerce uses excerpt as a short description. 

add_action('save_post_product', 'auto_generate_short_description', 25, 3); 
 
function auto_generate_short_description($post_id, $post, $update) { 
 
	if (!empty($post->post_excerpt)) { 
    	return; 
	} 
 
	$title = get_the_title($post_id); 
 
	$prompt = "Write a short 2-3 line product summary for: {$title}."; 
 
	$short_desc = generate_openai_content($prompt); 
 
	if (!empty($short_desc)) { 
    	wp_update_post([ 
        	'ID' => $post_id, 
        	'post_excerpt' => $short_desc 
    	]); 
	} 
} 

Step 6: Generate SEO Meta Description 

If you are using an SEO plugin like Yoast, you can update meta fields.

add_action('save_post_product', 'auto_generate_meta_description', 30, 3); 
 
function auto_generate_meta_description($post_id) { 
 
	$title = get_the_title($post_id); 
 
	$prompt = "Write an SEO meta description under 160 characters for: {$title}."; 
 
	$meta_desc = generate_openai_content($prompt); 
 
	if (!empty($meta_desc)) { 
    	update_post_meta($post_id, '_yoast_wpseo_metadesc', $meta_desc); 
	} 
} 

You can append this to the main description.

Step 7: Generate Product Features 

You can also generate bullet points.

function generate_product_features($title) { 
	$prompt = "List 5 key features of {$title} in bullet points."; 
 
	return generate_openai_content($prompt); 
}

Step 8: Add Admin Button (Optional) 

Instead of auto-generating on save, you may want a manual button. 

Add Button in Admin


add_action('add_meta_boxes', function() { 
    add_meta_box( 
        'openai_generate_box', 
        'Generate Content', 
        'render_generate_button', 
        'product', 
        'side' 
    ); 
}); 

function render_generate_button($post) { 
    echo '<button type="button" id="generate-content">Generate with AI</button>'; 
}

Then use AJAX to trigger generation.

Step 9: Improve Prompt Quality 

The quality of output depends heavily on your prompt. 

Example Advanced Prompt 

Write a detailed WooCommerce product description for [Product Name]. 

Include: 

– Introduction 

– Key features (bullet points) 

– Benefits 

– Use cases 

– Conclusion 

Tone: Professional and persuasive 

Target audience: Online shoppers 

 

Better prompts = better output.

Step 10: Handle API Limits and Errors 

  • Use caching to avoid repeated API calls 
  • Add error logging 
  • Set fallback content 
  • Respect rate limits 

Best Practices 

  1. Don’t Overwrite Manual Content

Always check if content already exists before generating. 

  1. Use Background Processing

For bulk products, use WP Cron or queues. 

  1. Review AI Content

AI is powerful but not perfect. Always review before publishing. 

  1. Optimize for SEO

Add keywords in prompts for better ranking. 

  1. Combine with ACF Fields

You can generate custom field data using ACF.

Use Case Examples 

Example 1: Bulk Product Import 

When importing products via CSV, auto-generate descriptions after import. 

Example 2: Dropshipping Stores 

Generate content instantly for supplier products. 

Example 3: Marketplace Websites 

Standardize listings across vendors.

Advantages of This Integration 

  • Reduces manual workload 
  • Speeds up product publishing 
  • Improves content quality 
  • Helps scale an e-commerce business 
  • Enhances user experience

Limitations 

  • Requires API cost management 
  • Needs human review 
  • May require prompt tuning 
  • Not ideal for highly technical or regulated products 

Future Enhancements 

You can extend this system further: 

  • Generate product images using AI 
  • Auto-translate product descriptions 
  • Generate FAQs dynamically 
  • Voice-based product descriptions 
  • AI-powered product recommendations 

Auto Generate WooCommerce Product Content with AI

The Way Forward

Integrating the OpenAI API with WooCommerce is a powerful way to automate product data generation. It not only saves time but also ensures consistent and high-quality content across your store. 

With just a few lines of code and smart prompts, you can transform how your WooCommerce store operates. Whether you’re managing a small shop or a large catalog, AI can significantly streamline your workflow. 

Start small, test your prompts and gradually expand automation. With the right implementation, this integration can become one of the most valuable tools in your e-commerce stack. 

You may also like: How AI Automation Enhances Customer Support in WooCommerce

Free Consultation

    Hemang Shah

    Hemang Shah serves as Assistant Vice President at iFlair Web Technologies Pvt. Ltd., bringing over 15 years of extensive IT experience and strategic leadership to drive successful project outcomes. He possesses a comprehensive understanding of technology, operations, and business alignment, and has consistently led teams and initiatives delivering high-quality, scalable, and efficient solutions across diverse industries.
    With a strong background in IT management and proven leadership and decision-making skills, he oversees complex projects, implements best practices, optimizes processes, and fosters a collaborative environment that empowers teams to achieve organizational objectives. His commitment to innovation, operational excellence, and client satisfaction has significantly contributed to the organization’s growth and success.



    MAP_New

    Global Footprints

    Served clients across the globe from38+ countries

    iFlair Web Technologies
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.