Every WooCommerce store has a Related Products section. Almost none of them are actually useful. The default block pulls items from the same category and tags, which means a customer buying a $400 camera lens gets recommended a $9 lens cap alongside a camera bag and a tripod, all technically “cameras,” none of them a smart suggestion. This guide is about fixing that. Specifically, it is about building genuine WooCommerce AI recommendations and WooCommerce personalization that run entirely on your own server, with no monthly SaaS fee and no customer data leaving your infrastructure.
The techniques here range from zero-code approaches using existing WooCommerce data to PHP-based implementations using lightweight machine learning libraries. You do not need a data science background. You do need access to your server and a willingness to think about your product catalog as data.
Why “Related Products” Is Not Personalization
WooCommerce’s built-in related products are similarity-based, not behavior-based. Two products are “related” if they share a category or tag. That logic made sense when ecommerce was new. Today, customers expect the store to know what they actually want, not just what section of the catalog they are browsing.
There is a meaningful difference between:
- Similarity-based recommendations: “This product is in the same category as what you are looking at.”
- Behavior-based recommendations: “Customers who bought this also bought these specific other items.”
- Personalized recommendations: “Based on this customer’s purchase and browsing history, these items are most likely to convert.”
Third-party recommendation engines like Nosto, Barilliance, and LimeSpot deliver the third type, but they do so by sending your customer data to their servers, charging a monthly fee that scales with revenue, and giving you limited control over the algorithm. For stores that want full data ownership, or that find SaaS fees eating into margin, building a self-hosted alternative is a realistic project.
If you want background on what existing AI-powered plugins offer before going the custom route, this overview of AI product recommendations for WooCommerce stores covers the plugin landscape in detail.
The Data You Already Have

Before writing a single line of code, take stock of what WooCommerce already records. Your wp_woocommerce_order_items table contains every product ID on every order ever placed. That is the foundation for collaborative filtering, the technique behind “customers who bought X also bought Y.”
Here is what WooCommerce stores by default:
| Data Type | Table / Source | Useful For |
|---|---|---|
| Order line items | wp_woocommerce_order_items + order_itemmeta | Co-purchase analysis (“also bought”) |
| Product views | WooCommerce sessions / custom tracking | View-based recommendations |
| Customer order history | wp_posts (orders) + wp_woocommerce_order_items | Repeat-purchase prediction |
| Product attributes | wp_terms + wp_term_relationships | Content-based filtering |
| Search queries | WooCommerce search logs (if enabled) | Intent detection |
| Cart abandonment | wp_woocommerce_sessions | Recovery-focused recommendations |
The order items table is the highest-value data source for most stores. A simple SQL query can tell you which product pairs appear together most frequently in the same order, and that frequency data is the raw material for a “frequently bought together” widget that actually reflects real customer behavior.
Building a Co-Purchase Recommendation Engine in PHP
This is the most practical starting point for most stores. The approach is straightforward: query the orders table to find which product pairs co-occur most often, cache the results, and display them on product pages. No external services, no data transfer, no ongoing fees.
Step 1: Query Co-Purchase Pairs
Add this function to your theme’s functions.php or a custom plugin:
This query joins the order items table with itself to find products that appear in the same order as your target product. Results are cached in WordPress transients for 6 hours to avoid running the query on every page load.
Step 2: Display Recommendations
Hook into WooCommerce’s product page output to render your recommendations:
This renders your data-driven recommendations using WooCommerce’s standard product template, which means they inherit your theme’s styling and respect sale prices, stock status, and add-to-cart logic automatically.
Customer-Level Personalization With Purchase History
Co-purchase analysis gives you good general recommendations. True personalization means knowing what a specific logged-in customer has bought before and recommending based on their individual history. WooCommerce stores this data, you just need to query it differently.
Tracking and using customer analytics data well is the foundation of any personalization effort. The WooCommerce reports and analytics guide explains how to interpret your store data before building on top of it.
This function aggregates co-purchase recommendations across everything the customer has ever bought, removes products they already own, and returns the items that appear most consistently in orders from customers similar to them. It is not neural-network personalization, but for most stores it outperforms the default related products block significantly.
Content-Based Filtering: Recommendations Without Order History
Co-purchase analysis requires transaction data. For new stores, new products, or guest visitors, you need a different approach. Content-based filtering recommends products that are similar to the one currently being viewed, but using more signals than WooCommerce’s default category/tag matching.
The idea is to represent each product as a vector of attributes, then compute similarity scores between products. Attributes you can use:
- Category (with weighted hierarchy, subcategory match scores higher than top-level category)
- Tags (exact tag matches score higher than partial overlaps)
- Price range (products within ±30% price range score higher)
- Product attributes (color, size, material, especially useful for variable products)
- Description keyword overlap (TF-IDF style, though simpler approximations work)
| Signal | Weight | Rationale |
|---|---|---|
| Same sub-category | 3.0 | Strong relevance signal |
| Same parent category | 1.5 | Moderate relevance |
| Shared tag | 1.0 per tag | Cumulative, more shared tags = higher score |
| Price within 30% | 1.5 | Customer is in the same budget bracket |
| Price within 60% | 0.8 | Minor price affinity |
| Same brand attribute | 2.0 | Brand loyalty is a strong predictor |
| Shared product attribute | 0.5 per match | Material, color, etc. |
Pre-compute these scores weekly or on product updates, store them in a custom table or post meta, and query them at display time. This gives you fast, accurate recommendations even for guest users and newly listed products.
Displaying Recommendations: Block Patterns and Shortcodes
Once you have the recommendation logic in place, you need to expose it in your theme. There are two practical approaches: a shortcode for Classic themes and page builders, and a block pattern for block-based themes.
Shortcode Implementation
Use this shortcode anywhere in your content: [woosell_recommendations limit="4" title="Customers Also Bought"]. It works in product descriptions, page content, and widget areas that support shortcodes.
Placement Strategy
Where you display recommendations affects click-through rate significantly. Tested placement options, ranked by typical performance:
- After add-to-cart button, high visibility, captures intent at peak moment
- After product description, good for considered purchases where customers read content
- Cart page sidebar, last upsell opportunity before checkout
- Order confirmation page, lower conversion but useful for cross-sell at post-purchase
- Shop/category pages, personalized grid based on recent views, lower intent context
Integrating With WooCommerce Loyalty Programs
Recommendations become significantly more powerful when they are connected to your loyalty and retention strategy. Surfacing recommendations like “Buy this to reach Gold status” or “These items earn 3x points this week” combines personalization with incentive in a way that drives both conversion and lifetime value.
The guide to customer loyalty programs for WooCommerce covers which plugins provide programmatic access to points data, which is what you need to combine recommendations with loyalty logic.
A basic pattern for loyalty-aware recommendations:
- Get the customer’s current loyalty tier and points balance from your loyalty plugin’s API
- Calculate how many points each recommended product would earn
- Boost the display score of products that would push the customer to the next tier
- Show a contextual label: “Earns 450 points, only 50 away from Gold”
This requires no third-party recommendation engine. It just requires connecting two data sources you already have: your order history and your loyalty plugin’s data.
Performance Optimization and Caching Strategy
Recommendation queries can be expensive if run on every page load. A caching strategy is not optional, it is a prerequisite for production deployment. Here is a layered approach that works at any scale:
| Layer | Method | TTL | Use Case |
|---|---|---|---|
| Database query cache | WordPress Transients API | 6 hours | Per-product co-purchase pairs |
| Customer recommendation cache | Transient + user meta | 1 hour | Per-customer personalized list |
| Pre-computed matrix | Custom table or object cache | 24 hours (cron rebuild) | Full-catalog similarity scores |
| Fragment cache | Output buffering + transient | 30 minutes | Rendered HTML blocks |
| Redis object cache | Redis/Memcached + WP plugin | Persistent | High-traffic stores (500+ concurrent) |
For most stores under 10,000 products and 50,000 orders, transient caching per product ID is sufficient. The query itself takes 50–150ms uncached; with transients it drops to under 1ms. Schedule a WP-Cron job to pre-warm the cache for your top 100 products during off-peak hours.
Measuring Recommendation Effectiveness
Building the system is only half the work. If you cannot measure whether recommendations are actually converting, you cannot improve them. Track these metrics at minimum:
- Recommendation click-through rate: What percentage of customers who see recommendations click at least one? (Benchmark: 5–15% for well-placed recommendations)
- Recommendation-to-purchase rate: Of customers who click a recommendation, what percentage complete a purchase of that item?
- Average order value lift: Do orders that include a recommended item have a higher AOV than those that do not?
- Items per order: Are customers buying more products per transaction since you added recommendations?
Track recommendation clicks by adding a URL parameter when recommendations are displayed: ?rec_source=copurchase. This lets you filter in Google Analytics or WooCommerce’s built-in reports to isolate recommendation-driven revenue without installing any additional tracking code.
Frequently Asked Questions
Do self-hosted AI recommendations require a machine learning library?
No. The co-purchase approach described in this guide is pure SQL and PHP, no ML library required. True machine learning (collaborative filtering with matrix factorization, neural network-based recommendations) does require libraries like PHP-ML or offloading computation to Python scripts via WP-CLI. But for stores with under 50,000 orders, the SQL-based approach typically delivers comparable recommendation quality to basic ML models, because the limiting factor is data volume, not algorithm sophistication. Start with the SQL approach, measure results, and add ML complexity only if you see diminishing returns.
How many orders do I need before co-purchase recommendations become reliable?
The minimum practical threshold is around 500 completed orders across at least 50 distinct products. Below that, co-purchase data is too sparse to produce meaningful recommendations, you will end up showing the same 2–3 popular products as recommendations for everything. With fewer orders, use content-based filtering (category, tags, price, attributes) instead. Between 500 and 5,000 orders, blend both approaches: use co-purchase data where it exists and fall back to content-based filtering for products with sparse transaction history.
Can I use these recommendations for email marketing without a third-party ESP?
Yes, with some additional work. WooCommerce’s transactional email system (via WC_Email) supports dynamic content hooks. You can call your recommendation functions in email templates to include personalized product sections in order confirmation and abandoned cart emails. The limitation is that email images must be absolute URLs, and you cannot use JavaScript for email rendering, but a static grid of recommended products with product images, names, and prices is entirely achievable. Tools like FluentCRM or AutomateWoo (which run locally) expose hooks that make this even more practical, as they have built-in support for WooCommerce product data in email templates.
Can I use recommendation data for upsell prompts at checkout?
Yes. WooCommerce’s checkout hooks – particularly woocommerce_checkout_after_order_review and woocommerce_thankyou – let you inject recommendation blocks directly into the checkout and order confirmation pages. Co-purchase recommendations at checkout can increase average order value by surfacing genuinely relevant add-ons at the moment of highest buyer intent. Keep checkout recommendations limited to 2–3 items maximum, prioritize low-friction additions like accessories or digital downloads, and avoid items that require additional configuration choices that could distract from completing the purchase.
How do I handle recommendations for guest customers without purchase history?
Guest customers have no account-level purchase history, so behavior-based personalization is limited to the current browsing session. Use a combination of content-based filtering (based on the product being viewed) and globally popular items in the same category as a fallback. You can also store a session-level browse history using WooCommerce sessions or browser localStorage to track products viewed during the current visit, then weight content-based recommendations toward items similar to the browsing pattern. This approach approximates personalization for first-visit guests without requiring account creation.
Advanced Techniques: Seasonality and Trend Weighting
Static co-purchase data has one significant limitation: it treats an order from three years ago the same as an order from last week. For most product categories, buying patterns change with seasons, trends, and inventory shifts. Adding time-decay weighting to your recommendation algorithm significantly improves relevance without meaningfully increasing complexity.
The simplest time-decay approach assigns a weight to each order based on how recent it is. Orders from the last 30 days get full weight (1.0), orders from 31–90 days get 0.7, orders from 91–180 days get 0.4, and older orders get 0.2. Multiply co-purchase frequency by this weight when computing recommendation scores.
For seasonal products (holiday decorations, summer gear, back-to-school supplies), you can also boost recommendations for products that have shown increased sales velocity in the current month compared to the rolling 12-month average. This requires tracking sales velocity per product, which WooCommerce’s analytics tables already enable with a simple query comparing current-period and prior-period sales counts.
Trend weighting is especially valuable for fashion, home decor, and lifestyle products where what sold well six months ago may no longer be relevant. For commodity products (hardware, office supplies, consumables), trend weighting matters less, the same items tend to be purchased together regardless of when.
A/B Testing Your Recommendation Strategy
No recommendation algorithm is universally optimal across all store types and customer bases. The only way to know which approach works best for your specific store is to test. WordPress does not have built-in A/B testing, but you can implement a lightweight test using user session splitting.
A simple approach: use the last digit of the customer’s session ID to split traffic. Sessions ending in 0–4 see co-purchase recommendations; sessions ending in 5–9 see content-based recommendations. Track which group generates higher average order values over a 4-week period using WooCommerce’s order notes or a custom meta field.
- Test duration: Run for at least 4 weeks to capture weekly buying patterns and enough statistical volume
- Sample size: Need at least 200 conversions per variant for statistical significance at 95% confidence
- Primary metric: Average order value (not click-through rate, clicks that do not convert are noise)
- Secondary metrics: Items per order, 30-day repeat purchase rate, recommendation click-through rate
Once you have a winner, do not stop testing. The optimal recommendation strategy for Q4 holiday shopping may be different from what works best in Q2. Build the habit of running at least one recommendation test per quarter to continuously improve performance and adapt to changing customer behavior and catalog mix.
Scaling Your Recommendation Engine as Order Volume Grows
When you first launch your recommendation engine, your order database will be sparse and content-based filtering will do most of the heavy lifting. As your store accumulates transaction history, the right recommendation strategy shifts. Here is a practical roadmap for evolving your approach as order volume grows:
- 0–500 orders: Content-based filtering only. Recommendations driven by shared categories, tags, price range, and product attributes. Reliable even with no transaction history.
- 500–5,000 orders: Blend co-purchase recommendations for products with sufficient history (5+ co-purchase pairs) with content-based filtering as a fallback. Monitor recommendation diversity to prevent popular products from dominating.
- 5,000–50,000 orders: Full co-purchase matrix viable for most of the catalog. Introduce customer-level personalization for logged-in users with 3+ purchases. Add time-decay weighting to keep recommendations current.
- 50,000+ orders: Consider matrix factorization or basic collaborative filtering using PHP-ML or a Python microservice called via
wp_remote_get(). At this order volume, algorithm quality matters more than data availability.
One common scaling mistake is allowing bestsellers to dominate recommendations across the entire catalog. A product appearing in 30% of all orders surfaces as a top recommendation for nearly every product, which is not useful. Implement a popularity cap: exclude products that already have high organic visibility, or weight recommendations away from your top 5% bestsellers. The goal is to surface relevant items the customer would not have discovered otherwise.
As your recommendation system matures, integrate it more deeply with other WooCommerce systems. Push high-affinity product pairs to your upsell and cross-sell meta fields so they appear in WooCommerce’s native upsell positions as well. Export recommendation data to your email marketing platform for abandoned cart sequences. Surface recommendations in search results for queries that produce few direct matches. Each integration point multiplies the value of the same underlying data.
Getting Started Today
Building self-hosted WooCommerce AI recommendations and WooCommerce personalization is not a weekend project if you want the full stack, but the co-purchase engine covered in this guide is a realistic one-to-two day implementation for a developer familiar with WordPress and WooCommerce hooks. The ROI case is straightforward: a 5% increase in items per order on a store doing $50,000/month in revenue is $2,500 in additional monthly revenue, recurring, with no ongoing platform fees.
Start with the SQL co-purchase query. Deploy it to a staging environment, validate the results against your actual order history, and measure click-through rate for two weeks before rolling out to production. In the first month, track average order value, items per order, and recommendation click-through rate as your three primary signals. The data you already have is likely better than you expect, and the recommendations engine is the piece that lets you use it. As your order volume grows, so does the quality of your recommendations – unlike SaaS tools that charge more as you scale, a self-hosted engine costs the same whether you have 1,000 orders or 100,000.
If you want to compare what plugins can do versus a custom build before committing to development time, the full AI recommendations plugin overview gives you the feature-by-feature comparison you need to make that decision with data.
