Hide Buy Button if not logged in

Ask the community for help and support.
Post Reply
Portman
Posts: 53
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 13 times
Been thanked: 1 time

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: 1822
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 33 times
Been thanked: 87 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
Ready to take on New Projects

If anyone has any small(ish) projects, feel free to PM me as I'm winding back up to full time online working.

Please note, I lost access to oscshops email address.
My new email is gb8231059 [at the same provider]
Portman
Posts: 53
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 13 times
Been thanked: 1 time

Re: Hide Buy Button if not logged in

Post by Portman »

I feel like an idiot, thanks
dodgyhuw
Posts: 10
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