Control modules on VirtueMart pages

(48 votes, average 4.29 out of 5)

Use these recipes to display different modules on different VirtueMart pages.

  • display a module only on the “Front Page” of VirtueMart
  • display a certain module when a certain product category is being listed
  • display a module only on the 1st page of a “shop.browse” list
  • display a module only to members in a particular VM shopper group
  • display a certain module when a certain product is being displayed in detail
  • show certain modules on various other VirtueMart pages, e.g. shopping cart, signup, any of the checkout pages, profile pages, search pages, etc etc.

Don’t forget to customise the module IDs that you are returning, to match the IDs of your own modules.

VirtueMart 2.x

This method is available only on Joomla 2.5, with VirtueMart 2.0.x.

Display module only on the “Front Page” of VirtueMart:

Using this simple recipe you can restrict modules to just the front page of VirtueMart. The “Front Page” is the one linked to from a menu item, not necessarily the front page of your site.

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = frontpage" ) ) return XXX;
/* replace XXX with the module id or position you want
 * to display <em>only</em> on the front page of VirtueMart
 */

Need to reverse that, and remove the modules from the Front Page of VirtueMart, and show them on any other VirtueMart pages? Try this one instead:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype != frontpage" ) ) return XXX;
/* replace XXX with the module id or  position you want
 * to display <em>except</em> on the front page of VirtueMart
 */

Targeting all other VM pages types

You can target modules onto any of VirtueMart page type, any combination of types, or exclude modules from a particular page type or types.

The full list of types is: account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, cart, cart.editpayment, cart.editshipment, cart.thankyou, category, searchresults, checkout.editbillto, checkout.editshipto, checkout.result, checkout.2Checkout_result, checkout.epay_result, checkout.ipayment_result, checkout.paysbuy, frontpage, order.view, orders, plugin.response, manufacturer, manufacturer.products (i.e. list of products from a manufacturer), productdetails, productdetails.ask, productdetails.mailquestion, productdetails.notify (i.e. when asking for notification when product is available), productdetails.recommend (i.e. when e-mailing page to others), shop.ask, shop.infopage, shop.registration, shop.savedcart, shop.search, shop.waiting_list, shop.waiting_thanks, user, user.editaddresscheckout, user.editbillto, user.editshipto

Target module onto 1 page (replace cart with any of the page types above):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = cart" ) ) return XXX;

Target module onto several pages:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = frontpage, cart" ) ) return XXX;

Exclude module from one or more pages:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( ! $vm->check( "pagetype = frontpage, shop.cart" ) ) return XXX;

Target module onto all "account" pages

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype starts with account" ) ) return XXX;

Remove modules from VM cart/checkout pages

i.e. “Show modules on all pages except VM cart/checkout pages”

You will need to put a MetaMod with the following PHP into each module position where the modules were appearing. For each one, return the module id (or an alternative module position) that you want to insert into that location.

One good technique is to place all the modules which were a position (e.g. "right") into a position called "right-non-vm". Then you assign the MetaMod into the normal "right" position, and instead of return XXX; below, use return "right-non-vm";  This makes it easy to add and remove modules from this position without having to edit the MetaMod to add/remove module ids.

The “pagetype” of all the checkout pages starts with the word "checkout", so this rule catches all of them: checkout.editbillto, checkout.editshipto, checkout.result etc. The “pagetype” of all the cart pages starts with the work “cart”, so this rule catches all of them too: cart, cart.editpayment, cart.editshipment, cart.thankyou.

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( ! $vm->check("pagetype starts with checkout, cart") ) return XXX;
/* replace XXX with the module id or position you want
 * to display <em>except</em> on any of the checkout or cart pages
 */

Display a certain module only on category pages, with a different module for each category:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check("pagetype = category") ) { 
  $category_id = $vm->info( "category_id" );
  /* when browsing a specific category on browse page (e.g. category 2) */
  if ($category_id == "2") return WWW; /* module WWW for category 2 */
  if ($category_id == "3") return XXX; /* module XXX for category 3 */
  if ($category_id == "4") return YYY; /* module YYY for category 4 */
 
  /* when browsing any other category page */
  return ZZZ;
}

Show a module only on the first (paginated) page of a “category” list:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = category" )
  and $jinput->get('limitstart') == 0 ) {
  /* replace XXX below with the module id or position you want to show on
     1st page of browse results. If you want to change this
     to only show the module on pages 2, 3, 4 ... etc then
     also change the "==" in the line above to "!="
   */
  return XXX; 
}

Show modules only to shoppers in a particular VM shopper group:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
/* for VM shopper group 6, use module XXX */
if ( $vm->check( "shopper_group = 6" ) ) return XXX; 
/* for shopper groups 7 and 8 use module YYY */
if ( $vm->check( "shopper_group = 7, 8" ) ) return YYY; 
else return ZZZ; /* for all other groups use module ZZZ */

Display a module on the detail page for certain products:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ($vm->check( "pagetype = productdetails" ) ) {
 
  $product_id = $vm->info( "product_id" );
 
  /* modules that should appear for specific products */
  if ($product_id == "4") return 99;
  if ($product_id == "44") return 100;
}

Show a module once a coupon has been redeemed

Display a module when any coupon has been redeemed:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "is_coupon_redeemed = true" ) ) return XXX;

Display a module when a specific coupon has been redeemed:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "coupon_code = MYDISCOUNTCOUPON" ) ) return XXX;

Show a module based on VM cart contents

Display a module when a particular item is in the cart:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" ) ) return XXX; /* if product 15 in cart */

Display a module when a particular item is in the cart and the user is on the Cart page:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" )
   and $vm->check("pagetype startswith cart" ) ) return XXX;

Display a module when either of two items are in the cart:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15, 21" ) ) return XXX;
/* show module XXX (replace with id) when either product 15 or 21 are in the cart */

Display a module when two particular items are both in the cart together:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" ) 
  and $vm->check( "cart_product_ids = 21" ) ) return XXX;
/* show module XXX (replace with id) when products 15 and 21 are both in cart together */

Show a module based on the particulars of the product being viewed

These recipes will only work when the user is viewing a product page or product query page.

Show a module if product is out of stock:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_in_stock = 0" ) ) return XXX;

Show a module if product is low in stock (1-10 items):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_in_stock >= 1" )
   and $vm->check("product_in_stock <= 10" ) ) return XXX;

Show a module if product is on special:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "is_product_special = true" ) ) return XXX;

Show a module if product is over 20 kilos/pounds in weight (the unit depends on the type of unit used for the product in the VM back end — this rule only checks the numbers, not the unit):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_weight > 20" ) ) return XXX;

Can’t find what you were looking for? There are even more JomGenius parameters for querying Virtuemart on the JomGenius Parameters page.

VirtueMart 1.x

This method is available from MetaMod 2.4 onwards.

Display module only on the “Front Page” of VirtueMart:

Using this simple recipe you can restrict modules to just the front page of VirtueMart. The “Front Page” is the one linked to from a menu item.

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = frontpage" ) ) return XXX;
/* replace XXX with the module id or position you want
 * to display <em>only</em> on the front page of VirtueMart
 */

Need to reverse that, and remove the modules from the Front Page of VirtueMart, and show them on any other VirtueMart pages? Try this one instead:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype != frontpage" ) ) return XXX;
/* replace XXX with the module id or  position you want
 * to display <em>except</em> on the front page of VirtueMart
 */

Targeting all other VM pages types

You can target modules onto any of VirtueMart page type, any combination of types, or exclude modules from a particular page type or types.

The full list of types is: frontpage, account.billing, account.index, account.order_details, account.orders, account.shipping, account.shipto, shop.browse, shop.ask, shop.cart, shop.infopage, shop.manufacturer_page, shop.product_details, shop.savedcart, shop.search, shop.waiting_list, shop.waiting_thanks, checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou

Target module onto 1 page (replace shop.cart with any of the page types above):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = shop.cart" ) ) return XXX;

Target module onto several pages:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = frontpage, shop.cart" ) ) return XXX;

Exclude module from one or more pages:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype not = frontpage, shop.cart" ) ) return XXX;

Target module onto all "account" pages

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype starts with account" ) ) return XXX;

Remove modules from VM checkout pages

i.e. “Show modules on all pages except VM checkout pages”

You will need to put a MetaMod with the following PHP into each module position where the modules were appearing. For each one, return the module id (or an alternative module position) that you want to insert into that location.

One good technique is to place all the modules which were a position (e.g. "right") into a position called "right-non-vm". Then you assign the MetaMod into the normal "right" position, and instead of return XXX; below, use return "right-non-vm";  This makes it easy to add and remove modules from this position without having to edit the MetaMod to add/remove module ids.

The "pagetype" of all the checkout pages starts with the word "checkout", so this rule catches all of them: checkout.index#1, checkout.index#2, checkout.index#3, checkout.index#4, checkout.thankyou.

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check("pagetype not starts with checkout") ) return XXX;
/* replace XXX with the module id or position you want
 * to display <em>except</em> on any of the checkout pages
 */

Display a certain module only on browse pages, with a different module for each category:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check("pagetype = shop.browse") ) { 
  $category_id = $vm->info( "category_id" );
  /* when browsing a specific category on browse page (e.g. category 2) */
  if ($category_id == "2") return WWW; /* module WWW for category 2 */
  if ($category_id == "3") return XXX; /* module XXX for category 3 */
  if ($category_id == "4") return YYY; /* module YYY for category 4 */
 
  /* when browsing any other category on browse page */
  return ZZZ;
}

Show a module only on the first (paginated) page of a “shop.browse” list:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "pagetype = shop.browse" ) ) {
  global $vm_mainframe;
  $category_id = $vm->info( "category_id" );
  $limitstart = $vm_mainframe->getUserStateFromRequest(
    "view{$category_id}limitstart", 'limitstart', 0 );
 
  /* replace XXX with the module id or position you want to show on
     1st page of browse results. If you want to change this
     to only show the module on pages 2, 3, 4 ... etc then
     also change the "==" to "!="
   */
  if ($limitstart == 0) return XXX; 
}

Show modules only to shoppers in a particular VM shopper group:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
/* for VM shopper group 6, use module XXX */
if ( $vm->check( "shoppergroup = 6" ) ) return XXX; 
/* for shopper groups 7 and 8 use module YYY */
if ( $vm->check( "shoppergroup = 7, 8" ) ) return YYY; 
else return ZZZ; /* for all other groups use module ZZZ */

Display a module on the detail page for certain products:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ($vm->check( "pagetype = shop.product_details" ) ) {
 
  $product_id = $vm->info( "product_id" );
 
  /* modules that should appear for specific products */
  if ($product_id == "4") return 99;
  if ($product_id == "44") return 100;
}

Show a module once a coupon has been redeemed

Display a module when any coupon has been redeemed:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "is_coupon_redeemed = true" ) ) return XXX;

Display a module when a specific coupon has been redeemed:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "coupon_code = MYDISCOUNTCOUPON" ) ) return XXX;

Show a module based on VM cart contents

Display a module when a particular item is in the cart:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" ) ) return XXX; /* if product 15 in cart */

Display a module when a particular item is in the cart and the user is on the Cart page:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" )
   and $vm->check("pagetype = shop.cart" ) ) return XXX;

Display a module when either of two items are in the cart:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15, 21" ) ) return XXX;
/* show module XXX (replace with id) when either product 15 or 21 are in the cart */

Display a module when a two particular items are both in the cart together:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "cart_product_ids = 15" ) 
  and $vm->check( "cart_product_ids = 21" ) ) return XXX;
/* show module XXX (replace with id) when products 15 and 21 are both in cart together */

Show a module based on the particulars of the product being viewed

These recipes will only work when the user is viewing a product page or product query page.

Show a module if product is out of stock:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_in_stock = 0" ) ) return XXX;

Show a module if product is low in stock (1-10 items):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_in_stock >= 1" )
   and $vm->check("product_in_stock <= 10" ) ) return XXX;

Show a module if product has sold more than 1000 items ("popular"):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_sales > 1000" ) ) return XXX;

Show a module if product is on special:

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "is_product_special = true" ) ) return XXX;

Show a module if product is over 20 kilos/pounds in weight (the unit depends on the type of unit used for the product in the VM back end — this rule only checks the numbers, not the unit):

$vm = JomGenius("virtuemart"); // need this at the start of every rule
if ( $vm->check( "product_weight > 20" ) ) return XXX;

Can’t find what you were looking for? There are even more JomGenius parameters for querying Virtuemart on the JomGenius Parameters page.

Pre-JomGenius (VM1.0)

If you have MetaMod 2.4 or more recent, try the "JomGenius" version instead of this one.

Display module only on the “Front Page” of VirtueMart:

Using this simple recipe you can restrict modules to just the front page of VirtueMart. The “Front Page” is the one linked to from a menu item.

Note that if you have several menu items pointing to several VirtueMart pages, this starts to get very confusing. Ask about it on the MetaMod Forums if you need a solution for that!

if ($option == "com_virtuemart" and JRequest::getVar("page") == null) return 101;
/* (replace 101 with the module number you want
 * to display only on the front page of VirtueMart)
 */ 

Need to reverse that, and remove the modules from the Front Page of VirtueMart, and show them on any other VirtueMart pages? Try this one instead:

if ($option == "com_virtuemart" and JRequest::getVar("page") != null) return 101;
/* (replace 101 with the module number you want
 * to display on all VirtueMart pages except the Front Page)
 */ 

Simple recipe to display a certain module only on browse pages, with a different module for each category:

if ($option == "com_virtuemart") {
 $category_id = JRequest::getVar("category_id");
 $category = JRequest::getVar("category", null);
 $page = JRequest::getVar("page");
 if ($page == "shop.browse") {
 
  /* when viewing ALL categories */
  if ($category === '') return 100; /* module 100 for "ALL" categories */
 
  /* when browsing a specific category on browse page (e.g. category 2) */
  if ($category_id == "2") return 101; /* module 101 for category 2 */
  if ($category_id == "3") return 102; /* module 102 for category 3 */
  if ($category_id == "4") return 103; /* module 103 for category 4 */
 
  /* when browsing any other category on browse page */
  return 98;
 }
}

Show a module only on the first (paginated) page of a “shop.browse” list:

if ($option == 'com_virtuemart' and JRequest::getVar('page') == 'shop.browse' ) {
  global $vm_mainframe;
  $category_id = vmRequest::getInt('category_id');
  $limitstart = $vm_mainframe->getUserStateFromRequest(
    "view{$category_id}limitstart",
    'limitstart',
    0 );
  /* replace 101 with the module you want to show on
     1st page of browse results. If you want to change this
     to only show the module on pages 2, 3, 4 ... etc then
     also change the "==" to "!="
   */
  if ($limitstart == 0) return 101; 
}

Show modules only to shoppers in a particular VM shopper group:

if ($user->usertype == "Registered") {
 $id = (int)$user->id;
 $query = "SELECT  shopper_group_id FROM #__vm_shopper_vendor_xref " .
   " WHERE user_id = '$id'";
 $db->setQuery( $query, 0, 1 );
 
 $row = $db->loadObject();
 $groupid = $row->shopper_group_id;
 if ($groupid == 6) return 101; /* for VM shopper group 6, use module 101 */
 else return 102; /* for all other groups use module 102 */
}

Display a module on the detail page for certain products:

if ($option == "com_virtuemart") {
 $page = JRequest::getVar("page");
 $product_id = JRequest::getVar("product_id"); 
 
 /* PRODUCT DETAILS page */
 if ($page == "shop.product_details") {
  /* modules that should appear for specific products */
  if ($product_id == "4") return 99;
  if ($product_id == "44") return 100;
 }
}

The all-in-one version that can detect just about any page within VirtueMart:

Don’t forget to customise the “return” numbers to return the module numbers that you actually want to appear.

if ($option == "com_virtuemart") {
 $page = JRequest::getVar("page");
 $category_id = JRequest::getVar("category_id"); 
 $product_id = JRequest::getVar("product_id"); 
 $search_category = JRequest::getVar("search_category"); 
 if ($search_category != "") { 
  if ($search_category == 1) return 95; /* searched for a specific category */
  return 96; /*searched on any other category */
 }
 
 /* BROWSE page */
 if ($page == "shop.browse") {
  /* when browsing a specific category on browse page (e.g. category 2) */
  if ($category_id == "2") return 97;
 
  /* when browsing any other category on browse page */
  return 98; 
 }
 
 /* PRODUCT DETAILS page */
 if ($page == "shop.product_details") {
  /* modules that should appear for specific products */
  if ($product_id == "4") return 99;
  if ($product_id == "44") return 100;
 
  /* when viewing a product in a specific category (2 in this case).
   * Doesn't always show up unfortunately: */
  if ($category_id == "2") return 101; 
  return 102; /* when viewing any other product not mentioned above */
 }
 
 /* "ask a question about this product" page */
 if ($page == "shop.ask") return 103;
 
 /* viewing shopping cart page */
 if ($page == "shop.cart") return 104;
 
 /* advanced search page */
 if ($page == "shop.search") return 1041;
 
 /* customer account page */
 if ($page == "account.index") return 1042;
 
 /* cutomer account shipping address page */
 if ($page == "account.shipping") return 1043;
 
 /* customer account add shipping address page */
 if ($page == "account.shipto") return 1044;
 
 /* customer account billing info page */
 if ($page == "account.billing") return 1045;
 
 /* page about saved carts */
 if ($page == "shop.savedcart") return 1046;
 
 /* order details page */
 if ($page == "account.order_details") return 1047;
 
 $last_step = JRequest::getVar("checkout_last_step");
 /* $last_step is:
  * "" on the first checkout page (as long as page is "checkout.index")
  * 1 on the page for shipping method,
  * 2 on the page for taking the credit card number
  * 3 on the page for reviewing the order
  * 4 on the page for confirming the order
  */
 
// now some more possible rules:
 /* checkout, before or after login: */
 if ($page == "checkout.index" &amp;&amp; $last_step == "" ) return 105;
 
 /* for selecting shipping method */
 if ($last_step == 1) return 106;
 
 /* page for taking the credit card number */
 if ($last_step == 2) return 107;
 
 /* page for reviewing the order */
 if ($last_step == 3) return 108;
 
 /* page for confirming the order */
 if ($last_step == 4) return 109;
 
}