Featured products with add to cart button

Today I want to show you how to create "Add to cart" button into the default prestashop Featured Products (homefeatured) module. This tutorial is based on default template but of course it will also works in non-default templates.


Add to cart button and homefeatured module

prestashop homefeatured add to cart button


Modification of the CSS styles

Open the /modules/homefeatured/homefeatured.css file. You've got there CSS styles related to the homefeatured module. At the end of this file you've got styles definition for Add to cart button:

#featured-products_block_center li .ajax_add_to_cart_button {display:none;}
#featured-products_block_center li span.exclusive {display:none;}

As you can see, styles related to the add_to_cart have got display:none; param. It mean, that add to cart button will not appear. Just change it to: display:block; exactly as I show below:

#featured-products_block_center li .ajax_add_to_cart_button {display:block;}
#featured-products_block_center li span.exclusive {display:block;}

After that just refresh your store front-end. You will see that "add to cart" buttons will appear. But "add to cart" text inside the each button isn't aligned well (not in the middle):

prestashop add to cart home featured


If you want to center the "add to cart" button, just add text-align:center; into the styles that I changed above. Final code:

#featured-products_block_center li .ajax_add_to_cart_button {display:block; text-align:center;}
#featured-products_block_center li span.exclusive {display:block; text-align:center;}


If you want to change the position of the "add to cart" button, you have to edit the .tpl file of the module. What I mean? I mean that you have to open the /modules/homefeatured/homefeatured.tpl file (or if exist: /themes/YOUR_THEME/modules/homefeatured/homefeatured.tpl)


you've got there definition of the button, which looks like:

{if ($product.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $product.available_for_order AND !isset($restricted_country_mode) AND $product.minimal_quantity == 1 AND $product.customizable != 2 AND !$PS_CATALOG_MODE}
  {if ($product.quantity > 0 OR $product.allow_oosp)}
    <a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&amp;id_product={$product.id_product}&amp;token={$static_token}&amp;add" title="{l s='Add to cart' mod='homefeatured'}">{l s='Add to cart' mod='homefeatured'}</a>
    <span class="exclusive">{l s='Add to cart' mod='homefeatured'}</span>
  <div style="height:23px;"></div>

Move it anywhere you want. You can change the postition of this code between the {foreach} {/foreach} tags. For example, you can move it above the price (as I show on the first image here). This is the code of price:

{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><span class="price">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}

Just paste the button code before code above. You will achieve the same effect as I:


prestashop homefeatured add to cart button


That's all. if you've got any questions related to this case - feel free to continue discussion below. Happy selling!

author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim