This article is best treated as an advanced follow-on guide.
The current plugin includes a built-in Products For You recipe inside the Product Collection block.
For most sites, that should be the default approach instead of building a custom REST-driven block from scratch.
Use the Product Collection block
- Insert the
Product Collectionblock in the editor. - Choose the recipe
Products For You. - Set the maximum number of products to show.
- Choose a fallback behavior.
- Save and test as a visitor with product history and segment data.
How recommendations are built
The current block recipe uses:
- Visitor activity history
- Visitor segment memberships
- WooCommerce product data
That makes it most useful when your site already has:
- Meaningful segments configured
- Product view and purchase activity being recorded
- Enough visitor history to distinguish likely interests
Fallback behavior
If the visitor does not have enough history yet, the block can:
- Show all products
- Hide itself
- Show a custom message
When to build a custom version
Build your own implementation only if you need a different recommendation model or a different front-end framework.
Advanced custom implementation example
If you go custom, a typical first step is to retrieve the visitor's active segments and combine that with your own product-selection logic.
async function fetchVisitorSegments(uid) {
const response = await fetch(
`${window.pwpSettings.root}personalizewp/v1/visitor-segments`,
{
method: "POST",
headers: {
"Accept": "application/json, */*;q=0.1",
"Content-Type": "application/json",
"X-PWP-Auth-Token": window.pwpSettings.apiToken
},
body: JSON.stringify({ uid })
}
);
const result = await response.json();
return result.success ? result.data : [];
}
From there you can:
- map segments to product collections
- combine segment data with recent activity
- apply your own scoring or merchandising rules
- render the output in a custom theme or headless component
If you go custom, the main references are: