0

I'm new to cartthrob and I want a functionality where if a user has purchased a product already then show out of stock to that user so that user can not make an order again. I'm using this code currently, it's working but as soon as I change entry status of that product purchased then this condition does not work. Please help

{if {exp:cartthrob:is_purchased_item entry_id="{entry_id}"} }
 You have already purchased this item!
{if:elseif {exp:cartthrob:is_in_cart entry_id="{entry_id}"}}
  <p class="text-center cart-button"><a href="/sample-products/cart" class="green-button">Go to cart</a></p>
{if:else}
{exp:cartthrob:add_to_cart_form class="form" secure_action="yes" return="/sample-products/cart" entry_id="{entry_id}" quantity="1"}
  <style>.form{border:0;}</style>
  <input type="hidden" name="item_options[purchased_type]" value="Sample Product"/>
  <input type="submit" name="submit" value="Add to Cart" class="green-button">
{/exp:cartthrob:add_to_cart_form}
{/if}
2
  • Looks like the code didn't come through.. Any chance you can try posting it again?
    – Tom Jaeger
    Nov 30, 2023 at 19:02
  • I've added the code now, please review.
    – Ram
    Dec 1, 2023 at 5:47

2 Answers 2

0

You didn't really outline the result of your code, but just reviewing it, I'm pretty sure it's the lack of quotes on your conditionals. This worked for me:

{if '{exp:cartthrob:is_purchased_item entry_id="{entry_id}"}' == '1'}
    You have already purchased this item!
{if:elseif '{exp:cartthrob:is_in_cart entry_id="{entry_id}"}' == '1'}
    <p class="text-center cart-button"><a href="/sample-products/cart" class="green-button">Go to cart</a></p>
{if:else}
     {exp:cartthrob:add_to_cart_form class="form" secure_action="yes" return="/sample-products/cart" entry_id="{entry_id}" quantity="1"}
    <style>.form{border:0;}</style>
    <input type="hidden" name="item_options[purchased_type]" value="Sample Product"/>
    <input type="submit" name="submit" value="Add to Cart" class="green-button">
    {/exp:cartthrob:add_to_cart_form}
{/if}
1
  • I get result as already purchased but the thing is as soon as I change the purchased product's entry status from paid to shipped, it does not work.
    – Ram
    Dec 4, 2023 at 8:14
0

UPDATE:

I've created own custom function which checks from the database if the current user has purchased item in the past and its working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.