Hide Buy Button if not logged in

Ask the community for help and support.
Post Reply
User avatar
Portman
Posts: 73
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 24 times
Been thanked: 4 times

Hide Buy Button if not logged in

Post 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
burt
Lead Developer
Lead Developer
Posts: 2050
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 35 times
Been thanked: 105 times

Re: Hide Buy Button if not logged in

Post 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
Please note, I lost access to oscshops email address.
My new email is gb8231059 [at the same provider]
User avatar
Portman
Posts: 73
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 24 times
Been thanked: 4 times

Re: Hide Buy Button if not logged in

Post by Portman »

I feel like an idiot, thanks
dodgyhuw
Posts: 11
Joined: Thu Jul 13, 2023 3:43 pm
Has thanked: 10 times

Re: Hide Buy Button if not logged in

Post by dodgyhuw »

Nice touch! In what other scenario may this be used to make our stores better?
Post Reply