Page 1 of 2

Remove Add to cart button from product listings

Posted: Sun Jul 02, 2023 5:24 pm
by bestmate
Hi, please can you guide me on how to remove the add to cart button from product listings pages(s) except on the product_info.php page? Also, how do I extend the view button to fill space after removing the add to cart part?
Phoenix.jpg
Thanks for assistance.

Re: Remove Add to cart button from product listings

Posted: Sun Jul 02, 2023 6:46 pm
by Kofod95
You could use css:
display: none;

I don't remember the exact classes, but something like:

Code: Select all

.is-product.btn-buy {
  display: none;
}
might be close enough?

//Daniel

Re: Remove Add to cart button from product listings

Posted: Sun Jul 02, 2023 8:14 pm
by burt
Depending on Phoenix version, you could be looking to take this file;

/templates/default/includes/components/product_card.php

And place a COPY of it into whatever template you are using. Eg if using the override template, it would go into;

/templates/override/includes/components/product_card.php

Now you can change that new file to suit your needs.

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 5:31 am
by heatherbell
bestmate wrote: Sun Jul 02, 2023 5:24 pm how to remove the add to cart button from product listings pages(s) except on the product_info.php page?
As in previous answer, this is a good case for using a template so make a copy as described in that answer.
Edit the copied file.
It is good to 'comment out' code instead of deleting it so comment out the code that displays the Buy Button.
The code for that is Lines 17-24 inclusive. (All references to line numbers are in an unchanged file).
It is PHP code so to comment out, add /* before Line 17 and add */ after Line 24.
Save the changes and the Buy Button disappears.
bestmate wrote: Sun Jul 02, 2023 5:24 pmhow do I extend the view button to fill space after removing the add to cart part?
With the Buy Button gone, there is now a div element that is not required, that is the btn-group on Line 13 (remember referring to line numbers in an unchanged file).
To make the View Button full width, that needs to go, so comment that out.
It is HTML code so to comment out the opening of the div, add <!-- before Line 13 and add --> after Line 13.
The closing of the div on Line 26 must also be commented out so add <!-- before Line 26 and add --> after Line 26.
With that div now gone, the View Button can be made full width.
The code for the that button is on Line 15.
Add w-100 to the button class, so after btn-view, add a space and then w-100.
Save the changes and you will now see this:
Screenshot 2023-07-03 062357.png
If this has helped develop your store, buy me a beverage.
If you are unable to DIY, we can do it for you.

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 8:35 am
by 14Steve14
We removed the BUY button from our site. We wanted people to actually click on the product to be sent to the product info page so they can read the product description, which is quite detailed. It has stopped people buying the wrong items, which is good.

We also centred all the text which just made everything look better.

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 4:56 pm
by bestmate
Thank you all for your help with this. I carefully followed the instructions by @burt to copy the product_card as follows:

from here /templates/default/includes/components/product_card.php

to here /templates/override/includes/components/product_card.php

And made the changes suggested by @heatherbell

I saved my file, cleared my cache and reloaded my page but there is not change to the button

Here's what I have in my file now:

Code: Select all

<a href="<?= $product->get('link') ?>"><?= tep_image('images/' . $product->get('image'), htmlspecialchars($product->get('seo_title')), '', '', '', true, 'card-img-top') ?></a>
  <div class="card-body">
    <h5 class="card-title"><a href="<?= $product->get('link') ?>"><?= $product->get('name') ?></a></h5>
    <h6 class="card-subtitle mb-2 text-muted"><?= $product->hype_price() ?></h6>
    <?= $card['extra'] ?? '' ?>
  </div>

<?php
  if ($card['show_buttons'] ?? false) {
?>

  <div class="card-footer bg-white pt-0 border-0">
<!--    <div class="btn-group" role="group"> -->
      <?php
    echo tep_draw_button(IS_PRODUCT_BUTTON_VIEW, '', $product->get('link'), null, null, 'btn-info btn-product-listing btn-view w-100');

/**    
if (!$product->get('has_attributes')) {
      echo PHP_EOL, tep_draw_button(
        IS_PRODUCT_BUTTON_BUY,
        '',
        tep_href_link(basename($GLOBALS['PHP_SELF']), tep_get_all_get_params(['action', 'products_id']) . 'action=buy_now&products_id=' . (int)$product->get('id')),
        null,
        ['params' => 'data-has-attributes="0" data-in-stock="' . (int)$product->get('in_stock') . '" data-product-id="' . (int)$product->get('id') . '"'],
        'btn-light btn-product-listing btn-buy');
    }
**/
?>
<!--    </div> -->
  </div>

<?php
  }
?>
What might I be doing wrong?

Thanks

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 5:22 pm
by heatherbell
bestmate wrote: Mon Jul 03, 2023 4:56 pm

Code: Select all

/**    
**/
What might I be doing wrong?
Not double checking your work!

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 5:28 pm
by bestmate
heatherbell wrote: Mon Jul 03, 2023 5:22 pm
bestmate wrote: Mon Jul 03, 2023 4:56 pm

Code: Select all

/**    
**/
What might I be doing wrong?
Not double checking your work!
@heatherbell

My apologies, please bear with me. I am a bit of a newbie and can't see what I've missed as I have changed the lines you quoted to
/*
*/

And there's no change to the button.

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 5:51 pm
by heatherbell
bestmate wrote: Mon Jul 03, 2023 5:28 pm And there's no change to the button.
Have you the correct template selected in Configuration>My Store

Re: Remove Add to cart button from product listings

Posted: Mon Jul 03, 2023 5:55 pm
by bestmate
@heatherbell

Yes, I do
template.jpg