This is a nifty little hack I found for Magento which enable you to hide your empty cart and compare product widgets, as in my opinion they are irrelevant if empty and take up precious page real estate.
Compare widget:
- Get your sidebar.phtml from:
public_html/app/design/frontend/base/default/template/catalog/product/compare/
- Add this to the top:
helper('catalog/product_compare')->getItemCount()>0): ?>- Add this to the bottom:
- so that you end up with something like this:
helper('catalog/product_compare')->getItemCount()>0): ?>
helper('catalog/product_compare');
$_items = $_helper->getItemCount() > 0 ? $_helper->getItemCollection() : null;
?>
__('Compare Products') ?>
getItemCount() > 0): ?>
__('(%d)', $_helper->getItemCount()) ?>
getItemCount() > 0): ?>
$_item): ?>
-
__('Remove This Item') ?>
helper('catalog/output')->productAttribute($_item, $_item->getName(), 'name') ?>
__('You have no items to compare.') ?>
Cart Widget:
- Get your sidebar.phtml from:
public_html/app/design/frontend/base/default/template/checkout/cart/
- Add this to the top:
getSummaryCount() ?> 0): ?>
- Add this to the bottom:
- so that you end up with something like this:
getSummaryCount() ?> 0): ?> getIsNeedToDisplaySideBar()):?>getSummaryCount() ?>__('My Cart') ?>0): ?>isPossibleOnepageCheckout()): ?>__('There is 1 item in your cart.', $this->getUrl('checkout/cart')) ?>
__('There are %s items in your cart.', $this->getUrl('checkout/cart'), $_cartQty) ?>
canApplyMsrp()): ?> __('Cart Subtotal:') ?> formatPrice($this->getSubtotal()) ?> getSubtotalInclTax()): ?>
(formatPrice($_subtotalInclTax) ?> getIncExcText(true) ?>)getChildHtml('extra_actions') ?>getRecentItems() ?>__('Recently added item(s)') ?>
__('You have no items in your cart.') ?>
Works in Magento ver. 1.6.2.0…
excellent!
Very handy bit of code thanks. Should work like this out the box really.
Hello, this helped me. However, the “Checkout” button still appears on sidebar. How can I hide it when cart is empty? Thanks.