Capture last viewed category in product view in Shopp Plugin for WordPress

Problem: I’m using the Shopp 1.1.9 ecommerce plugin for WordPress, and my client wanted to display specific background images while showing certain products. Shopp is very complete, but one thing that is missing in the current version ‘out of the box’ is the ability to pull the ‘last viewed’ category name when viewing a product. Obviously a product can belong to more than one cat, so it can’t know which one to display…

Fix: There is however a breadcrumb template tag that stores the category name that a user us currently viewing, so that if they then click on a product, the hierarchical parent category can be displayed in the breadcrumb.

This functionality can be used in a new custom tag. Jon Davis the lead developer of Shopp helped me a lot today as I was barking up the wrong tree going about it the wrong way.

Add this to your theme’s functions.php:

add_filter('shopp_tag_catalog_lastcat','get_last_cat');
function get_last_cat ($result,$options,$Object) {
    $Storefront = ShoppStorefront();
    if (false === $Storefront) return false;
    $category = $Storefront->breadcrumb;
    return $category;
}

Then anywhere in your Shopp templates you can do this to return the category part of the current breadcrumb e.g “Smalls” in Home > Smalls > Purple Pants :

<?php
//echo it out straight away..
shopp('catalog','lastcat');
 
// return it for use..
$lastcat = shopp('catalog','lastcat','return=true');
?>

Hope that helps someone, props go to JD for getting it working!

Leave a Reply

Your email address will not be published.