Is there any way in expresso to check if the current user has purchased a particular product?
Something like, {if purchased}you own this{if:else}you don't own this{/if}
Thanks
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityIs there any way in expresso to check if the current user has purchased a particular product?
Something like, {if purchased}you own this{if:else}you don't own this{/if}
Thanks
You will need Stash to get this working
Setting the stash
{if logged_in}
{exp:store:orders member_id="CURRENT_USER" paid="yes"}
{if is_order_paid}
{exp:stash:append name="verify_product" trim="yes"}
{items}{entry_id}|{/items}
{/exp:stash:append}
{/if}
{/exp:store:orders}
{/if}
Output the variables
Wrap exp:channel:entries
loop with {exp:stash:parse process="end"}{/exp:stash:parse}
Inside the entries loop
{if "{exp:stash:verify_product}" ~ "/{entry_id}\b/"}
You have already brought this map
{if:else}
{exp:store:product entry_id="{entry_id}" return="{current_path}"}
{if qty_in_cart}
This product is already in your cart.
{if:else}
{price} <input type="text" name="item_qty" value="1" /> <button type="submit">Add to cart</button> <button type="submit">Add to cart</button>
{/if}
{/exp:store:product}
{/if}
Disclamer: You will need latest version of EE to use the Matches operator conditional