Conditional Product Recommendations for WooCommerce self-updates
Conditional product recommendations for WooCommerce based on cart rules.
by SeaMKT · github.com/phamdinhtri123/conditional-product-recommendations
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/phamdinhtri123/conditional-product-recommendations/archive/refs/heads/main.zipShips its own WordPress updater (Plugin Update Checker), so new versions show up under Dashboard → Updates.
Displays conditional WooCommerce product recommendations on product pages, Classic Cart, and Classic Checkout.
Installation
- Copy this plugin folder to
wp-content/plugins/conditional-product-recommendations. - Make sure WooCommerce is installed and active.
- Activate Conditional Product Recommendations for WooCommerce in WordPress Admin.
- Go to WooCommerce > Product Recommendations.
Public GitHub Updates
This plugin bundles Plugin Update Checker and can update from a public GitHub repository.
Recommended flow:
VSCode
Git commit + push
GitHub public repository
Tag / Release v1.0.3
WordPress sites see "Version 1.0.3 is available"
Update now
Set the repository URL in conditional-product-recommendations.php:
define( 'CRW_GITHUB_REPOSITORY_URL', 'https://github.com/your-org/conditional-product-recommendations/' );
Optional, if you want updates to use a stable branch instead of releases/tags:
define( 'CRW_GITHUB_BRANCH', 'main' );
For each release:
- Update the plugin header
Version, theCRW_VERSIONconstant, andreadme.txtstable tag. - Commit and push.
- Create a Git tag like
v1.0.3. - Create a GitHub Release from that tag.
- WordPress sites will detect the update from the public GitHub release.
Create Your First Rule
- Click Add New.
- Enter a rule name, for example
Recommend BAC. - Search and select one or more Products to Display.
- Choose one or more locations: Product Page, Cart, Checkout.
- Save the rule.
Products already in the cart are hidden automatically. If all selected display products are already in the cart, the whole recommendation section is hidden.
Class Overview
CRW_Plugin: bootstraps the plugin, checks WooCommerce, registers the CPT, and wires services.CRW_Admin: renders the WooCommerce admin submenu, rule list, and rule form.CRW_Rule_Repository: stores rules in thecrw_recommendationCPT and post meta.CRW_Cart_Condition_Service: centralizes simple product, variable product, and variation cart detection.CRW_Rule_Evaluator: evaluates enabled/location/condition checks and filters invalid display products.CRW_Frontend: registers frontend hooks and uses one renderer for product, cart, and checkout locations.CRW_Ajax: securely adds recommended products to cart and returns mini-cart fragments.
Test Cases
- Display products are
AandB, cart is empty: both products appear. - Display products are
AandB, cart containsA: onlyBappears. - Cart contains all display products: the recommendation section is hidden.
- Two rules return the same product at one location: the product appears once.
- Click the
+button: product is added by AJAX, mini-cart fragments update, and that card disappears. - Disable a rule: it no longer renders anywhere.
- Select a variation as a display product: the AJAX add uses the parent product plus variation ID.
Classic vs Blocks
This version supports WooCommerce Product Page hooks, Classic Cart, and Classic Checkout. Cart Block and Checkout Block support should be added as a separate integration layer, for example class-blocks.php or class-store-api.php, while reusing the existing repository, cart service, and evaluator.