Conditional Gallery2 Shopping Cart Block

I am in the process of developing a photography website, and for that purpose I am combining WordPress + Gallery2.

Gallery2 has a very neat shopping cart feature, which lets a viewer select images, and then purchase/download, order prints, email etc in one go.

Gallery2 comes with a “Shopping Cart Info” block (a design element) which shows the contents of the cart. If selected, this block will display itself, whether or not there is actually anything within the cart.

I thought it looked a little tacky for the site to show a shopping cart on the gallery, and sub-gallery pages when there is nothing in it.

My solution to this issue was to create a new block, called “Conditional Cart Info”, which invokes the original “Shopping Cart Info”, only if the contents of the cart is greater than 0.

It requires a modification to the file /modules/cart/templates/blocks/ and the creation of a new file /modules/cart/templates/blocks/ConditionalCart.tpl.

You can download my modified files here or click through below to read the source code:


Code for modified

$blocks = array(
    'ShowCart' => array(
    'description' => $gallery->i18n('Shopping Cart Info')),
    'ConditionalCart' => array(
    'description' => $gallery->i18n('Conditional Cart Info'))

Code for new ConditionalCart.tpl :

 * $Revision: 1 $
 * Read this before changing templates!
{g->callback type="cart.LoadCart"}
{if ($ > 0)}
{ g->block type="cart.ShowCart" }

Leave a Reply


Contact Nixz Kerr