Page 1 of 1

Hide Buy Button if not logged in

Posted: Mon Sep 18, 2023 3:04 am
by Portman
Hi Everyone,

Sorry, its been a few years since I have played around with my store and have forgotten most of what I had learnt...

I feel like this should be an easy one that people have done multiple times before, but I just cant get it...

I want to hide the Buy button if a customer is not logged in.

I have added;

Code: Select all

if ( isset($_SESSION['customer_id']) ) {
to the top of tpl_cm_pi_buy_button.php but this is generates an unexpected if statement error.

any help would be appreciated

Re: Hide Buy Button if not logged in

Posted: Mon Sep 18, 2023 9:08 am
by burt
Assuming you are using override template;

1. Undo any changes you have made, and drop a COPY of
/includes/modules/content/product_info/templates/tpl_cm_pi_buy_button.php
to
/templates/override/includes/modules/content/product_info/tpl_cm_pi_buy_button.php

2. In that new template file;

Code: Select all

<?php
if (isset($_SESSION['customer_id'])) {
  ?>
 The content of the file, unchanged.
<?php
}
?>
Sounds like you (a) are not using the overridable features we've introduced and (b) forgot about <?php tags

Re: Hide Buy Button if not logged in

Posted: Tue Sep 19, 2023 4:33 am
by Portman
I feel like an idiot, thanks

Re: Hide Buy Button if not logged in

Posted: Fri Sep 22, 2023 5:25 pm
by dodgyhuw
Nice touch! In what other scenario may this be used to make our stores better?