• Blog
  • How to Connect OpenAI for AI Product Recommendations in WooCommerce

How to Connect OpenAI for AI Product Recommendations in WooCommerce

October 2, 2026
How to Connect OpenAI for AI Product Recommendations in WooCommerce
Quick answer

AI-powered product recommendations read your cart contents and order history to suggest products that actually fit what you are buying, not a static list. WooCommerce AI product recommendations connects your WooCommerce store to OpenAI, letting you build upsell and cross-sell rules that drive measurable revenue lift. A third of eCommerce revenue now flows through personalized recommendations instead of generic defaults.

Why AI Product Recommendations Matter in WooCommerce

Manual upsells have a ceiling. You pick a handful of products, assign them to a category, and every shopper sees the same three tiles whether they are buying a $12 phone case or a $900 laptop. OpenAI changes the input: it reads the cart contents, the product catalog, and the shopper's order history, then ranks candidates by fit rather than by whoever set the rule last.

The revenue case is documented: according to a Barilliance study, over 31% of eCommerce revenue was generated using personalized product recommendations. That is roughly a third of the money moving through a store, tied to what appears next to the product the shopper is already viewing.

WooCommerce stores have an advantage: because WooCommerce is self-hosted, your catalog data, order history, and customer records already sit in your own database. You are not asking a third party to enrich a product feed you cannot see. You are pointing an API call at data you already control.

How to Set Up WooCommerce Product Recommendations

Once the plugin is active, you will have live AI recommendations on your store within minutes. The setup flow is straightforward: connect your OpenAI account, create a rule, and choose where it should appear.

Step 1: Download and Activate the Plugin

  1. Download the plugin ZIP file from your WooCommerce account or the extensions section.
  2. In your WordPress admin, go to Plugins then Add Newthen Upload Plugin.
  3. Select the ZIP file, click Install Nowthen click Activate Plugin.

You should now see a new Product Recommendations entry under the WooCommerce menu in your admin sidebar.

Step 2: Configure OpenAI API Authentication and Model Selection

Before the plugin can generate recommendations, it needs access to your OpenAI account. Navigate to WooCommerce, then Settings, and then Product Recommendations AI Configurations tab.

  • OpenAI API Key: Paste your OpenAI API key here. This key authenticates your store with OpenAI's servers so recommendations can be generated on the fly.
  • Generation Models: Choose which OpenAI model to use for generating recommendations. Your options are GPT-3.5 Turbo, GPT-4, GPT-4 Turbo, GPT-4o Mini, and GPT-4o. Faster models (like GPT-3.5 Turbo) cost less and respond quicker; larger models (like GPT-4o) produce more nuanced suggestions.
  • Cache Duration (Days): Set how many days generated upsell recommendations are stored before the plugin refreshes them. This reduces repeated API calls, which saves money and keeps your storefront fast.
  • Validate Connection: Click this button to test whether your API key is valid and your account has available credit. Save all settings first, then validate.

Save your settings before clicking Validate Connection or the test has nothing to check.

Step 3: Toggle Default WooCommerce Recommendation Blocks

On the General Settings tab, decide whether to keep or disable WooCommerce's built-in recommendation widgets, which run independently of AI recommendations.

  • Display Default Related Products: Keep enabled if you want WooCommerce's standard related products block to appear on product pages, or disable it if you want only your custom AI rules to show.
  • Display Default Cross-Sell Products: Keep enabled if you want the default cross-sell block on the cart page, or disable it to replace it entirely with AI-powered rules.
  • Display Default Upsell Products: Keep enabled if you want WooCommerce's standard upsell block on product pages, or disable it to use only AI-generated upsells.

You can run both at the same time, but most stores disable the defaults to avoid duplicate recommendations and keep the page cleaner.

Step 4: Create Your First Recommendation Rule

Add New Rule and fill in the core settings that control what gets recommended and where.

  • Rule Name: A label you will recognize in the list later, such as "Laptop Upsells" or "Accessory Cross-sells."
  • Enable/Disable: Toggle whether this rule is active right now or paused.
  • Rule Priority: When multiple rules target the same placement, lower numbers run first. For cross-sell rules, priority is evaluated for each placement independently.
  • Recommendation Mode: Choose Custom to build your own filters and ranking rules, or choose AI to let OpenAI select products based on the full cart and order context.
  • Rule Type: Select Upsell to suggest higher-value versions of the current product, or Cross-sell to suggest complementary items.
  • Placement: Choose one or more locations where recommendations should appear: Product PageCart Page or Checkout Page.
  • Enable Randomization: Toggle this on to shuffle which products appear each time, or leave it off to show the same set every time based on your filters and ranking.

Randomization only applies in Custom mode and does not affect AI-generated recommendations.

Step 5: Add Cross-Sell Context Options (Cross-Sell Rules Only)

If your rule type is Cross-sell two additional options appear below the basic settings:

  • Include Cart Categories: When enabled, the plugin considers products in the same categories as items currently in the cart when building the recommendation list. This keeps cross-sells contextual to what the shopper is already buying.
  • Include User Purchase History: When enabled, the plugin pulls data from the shopper's past orders and suggests products that complement what they have bought before. This makes recommendations feel personal rather than generic.

Both options work best when your products are assigned to meaningful categories and when you have customers with order history in your store.

Step 6: Build Product Selection Filters and Ranking (Custom Mode Only)

If you chose Custom mode, you can now add filters that narrow which products are eligible for recommendation. Add one or more filters by selecting a filter type and condition:

  • Category: Show only products in a specific category.
  • Stock Status: Show only in-stock products, or include out-of-stock items.
  • Product Type: Show only simple products, variables, bundles, or other types.
  • Tags: Show only products tagged with specific keywords.
  • Price Range: Show only products within a specific dollar range.
  • Featured: Show only products marked as featured.
  • On Sale: Show only products currently on sale.

When you add multiple filters, only products matching all conditions survive. A store that combines a Category filter with a Price Range filter will narrow results quickly, so test whether you get enough recommendations.

Next, set how the surviving products are sorted:

  • Ranking Factor: Choose the sorting criterion: Popularity, Price, Rating, Sales, Stock, or Newness.
  • Sort Direction: Choose High to Low (expensive first, highest-rated first, or newest first) or Low to High (cheapest first, oldest first).

A store chasing average order value typically ranks by Price (High to Low) or Sales. A store trying to clear old inventory might rank by Newness (Low to High).

Step 7: Configure Display Settings and Copy the Shortcode

Scroll down to the Display Settings section and configure how the recommendations appear on the storefront:

  • Widget Title: The heading displayed above the recommendation block, such as "Frequently Bought Together" or "You Might Also Like."
  • Widget Description: A short descriptive line that appears below the title.
  • Default Products to Show: The number of product tiles to display in the recommendation block. A typical range is 3 to 6.
  • Show Add to Cart Button: Toggle whether each recommended product displays an Add to Cart button, allowing one-click purchases.
  • Show Price: Toggle whether each product's price is displayed next to its image.
  • Shortcode: A shortcode unique to this rule that you can copy and paste onto any page, post, or custom template to display the recommendations outside of the default placements.

Each rule generates its own shortcode, so you can place different recommendation blocks in different locations across your store.

Method 2: Custom OpenAI Integration via REST API and PHP

Developers who need full control over recommendation logic, styling, or model selection can build a custom integration using the OpenAI API and WordPress REST endpoints. This approach requires knowledge of PHP, theme templates, and WordPress hooks.

⚠️
Warning Never store your OpenAI API key in theme files, plugin code, or version control. Always use WordPress environment variables, configuration constants, or a secure secrets manager. Rotate keys regularly and use separate keys for staging and production.

Step 1: Generate a Dedicated OpenAI API Key

Log into your OpenAI account dashboard and create a new API key. Give it a recognizable name tied to your WooCommerce store so you can revoke it later without confusion. Copy the full key value immediately (it is shown only once), then set a monthly usage limit to prevent surprise charges.

Step 2: Store the Key and Register a Custom REST Endpoint

Add your API key to wp-config.php as a PHP constant, keeping it outside your theme and plugin files. Register a custom REST route using register_rest_route() with a permission callback that validates requests. Define and validate the product ID parameter in your callback function so malformed requests fail before reaching OpenAI. Your endpoint builds the OpenAI request payload, makes the call, and returns a sanitized JSON response of recommended product IDs.

Step 3: Assemble Product Context Data for the Model

OpenAI has no built-in knowledge of your catalog, so every request must include enough product detail for the model to make reasonable suggestions. Load the current product using wc_get_product(), then build a compact context array with the product's name, category, price, and key attributes. Query your catalog with wc_get_products() to build a candidate pool list containing product names and IDs.

Do not send your entire catalog on every request. Limit candidates to products in the same or adjacent categories, or use a price range filter, to keep API costs reasonable and response times fast.

Step 4: Call the OpenAI API and Validate the Response

Use wp_remote_post() to send a POST request to the OpenAI chat completions endpoint. Include your API key as a bearer token in the headers. Instruct the model to return only product IDs from your candidate list, formatted as JSON with no extra commentary. Decode the response with json_decode(), then verify that each returned product ID actually exists in your catalog and is published before using it.

Step 5: Cache Results and Render Them on the Storefront

Store the returned product IDs in a transient using set_transient() keyed by product ID and an expiration time that matches how often your catalog changes. Hook into woocommerce_after_single_product_summary for product page placement and woocommerce_cart_collaterals for cart placement. Load each cached product ID with wc_get_product() and output the standard WooCommerce product loop HTML.

Consideration

What to plan for

Cost control

Cache aggressively and limit candidate products per request

Failure handling

Fall back to WooCommerce related products if the API call times out or fails

Maintenance

You own error handling, model updates, and prompt refinement long-term

This approach gives you complete control, but it also means every edge case becomes your responsibility. If you want the same outcome without managing API logic, the plugin method gets you there faster.

Troubleshooting AI Recommendations in WooCommerce

If Your API Key Is Rejected

Re-verify the key in your OpenAI dashboard, confirm your account has active billing and available credit, and ensure no trailing spaces were copied. Check the Validate Connection result against your OpenAI usage log to confirm the request is leaving your server.

If Recommendations Are Not Displaying

Confirm the rule's Placement matches the page you are testing (Product Page, Cart Page, or Checkout Page are independent checkboxes). Verify the rule status shows enabled in the Recommendation Rules list. If you need placement outside the defaults, copy and paste the rule's Shortcode onto the target page instead. Clear your site cache and test in a private browser window.

If Recommendations Feel Generic or Irrelevant

Poor suggestions usually indicate thin product data rather than a model problem. Write descriptive product titles, assign every product to meaningful categories, and add relevant tags. For cross-sell rules, enable Include Cart Categories and Include User Purchase History to give the model more behavioral context.

Conclusion

AI-powered product recommendations convert browsers into buyers by showing the right product at the right moment, not a static fallback. Setting up AI Product Recommendations takes minutes, connects to your existing WooCommerce data without data export or third-party feeds, and gives you full control over rules, caching, and placement. Start with one rule on your product page, validate the quality of recommendations, then expand to cross-sells on the cart page once you trust the output.

Frequently Asked Questions

Do I need WooCommerce Subscriptions to use AI recommendations?+–
No. AI Product Recommendations works on any WooCommerce store regardless of whether you sell subscriptions, standard products, or both. WooCommerce Subscriptions is a separate optional extension.
What happens when my OpenAI quota runs out?+
Recommendation generation fails, and the widget either shows nothing or falls back to your default WooCommerce related products (depending on your General Settings configuration). Set a monthly spend cap in your OpenAI account dashboard to avoid surprise bills, and increase Cache Duration (Days) so existing recommendations are reused longer.
Can I use Anthropic, Azure OpenAI, or another AI provider instead?+
The official plugin only supports OpenAI. To use a different provider, build a custom integration following Method 2 and modify the API endpoint and authentication to match your chosen provider.
How long should I set the Cache Duration?+
Set it based on how fast your catalog changes. A store updating inventory weekly should use 7 days; high-traffic stores with frequent updates might use 1-3 days; slower stores might use 30 days. Shorter durations mean fresher recommendations and higher API costs; longer durations mean lower costs but staler suggestions.

Share Article

  • support widget30-day money back guarantee
  • support widgetDedicated Support Team
  • support widgetSafe & Secure Free Update
  • support widgetSafe Customized Solutions