Jump to content

[SOLVED] Hide Add To Cart Button until logged in


Recommended Posts

I haven't found an answer to this anywhere, so I hope someone here can help me. I would like to hide the add to cart button when a user is not logged in, but show it after log-in. Is this possible? Thanks in advance.

Link to comment
Share on other sites

it is possible, you can do it as following.

Here I am using product page as an example
1. Add following line to your product.php file

Before following line

$smarty->display(_PS_THEME_DIR_.'product.tpl');



Add line

$smarty->assign('logged', $cookie->isLogged());



2. Find the code for "add to cat" button/link in product .tpl file , then add {if $logged} before that code and {/if} after that code.

Here is example
"Add to cart" button code before change

<a class="exclusive button ajax_add_to_cart_button" href="{$base_dir}cart.php?qty=1&id_product={$accessory.id_product|intval}&token={$static_token}&add" rel="ajax_id_product_{$accessory.id_product|intval}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>




code after change

{if $logged}
<a class="exclusive button ajax_add_to_cart_button" href="{$base_dir}cart.php?qty=1&id_product={$accessory.id_product|intval}&token={$static_token}&add" rel="ajax_id_product_{$accessory.id_product|intval}" title="{l s='Add to cart'}">{l s='Add to cart'}</a>
{/if}

Link to comment
Share on other sites

it is possible, you can do it as following.
Find the code for "add to cat" button/link in related .tpl file(such as product.tpl), then
add {if $logged} before that code and {/if} after that code.



I tried this suggestion, and after refreshing the product page, the entire right column was missing, along with the page center including product image and information. This was the product.tpl file found in themes/prestashop. I tried to paste the line of code as modified into this post, but when I reviewed the post before adding it to the thread, most of the code was missing.

I restored the original product.tpl file and all the missing information reappeared...along with the add to cart button. Is there any other way to accomplish this?
Link to comment
Share on other sites

I have updated my previous post to make it more detailed with example.
Please go check that post again and hope that helps.


THANK YOU THANK YOU THANK YOU!!! I had been struggling with this issue for at least a couple of days now. I had the bracketed "if"s in all the right places, but wasn't aware of the need to edit the product.php file. That made all the difference!

Now if I can just figure out how to edit the topic title for this thread to show it is resolved! LOL
Link to comment
Share on other sites

  • 3 months later...

I was looking for this... I would like to ask how to hide both prices and cart until the user has logged in.
I really need presta shop to work as a catalog showing items but no prices or Cart until the customer logs in (I'm manually creating accounts for customers)

Could you help me PLEASE.

I'm using 1.3.6

Link to comment
Share on other sites

I tried the above to the tee... and NOTHING HAPPENED at all.

The add to cart button still shows even when not logged in.

I also tried placing {if $logged} at the top of blockcart.tpl and {/if} at end and again nothing changed!

Willing to pay someone to get this working for me!

Link to comment
Share on other sites

  • 1 year later...
  • 7 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...