Detecting Virtuemart pages through conditional statements

Here in this post I am sharing a way to detect if your current visited page is a VirtueMart page, category page or product detail page.

I think most of you might have experienced that when your client asked you to show/hide any particular section of VirtueMart pages so that they might be from the sidebar or somewhere else and that was placed in the default template file. Now in this case, you have only 2 options: either prepare a new template for VirtueMart pages or prepare hidden menus for each product and category pages, which actually takes time and is sometimes not feasible in the case of a large number of products and categories.

Virtuemart Conditional Statements

So, to eliminate such a situation, you can place conditional statements to detect Virtuemart pages, which is quite simple and easy to manage. For that, you simply have to place the below code in your template’s index.php to show/hide any section, module or else very easily.

CONDITION TO DETECT – IF VIRTUEMART PAGE

The below code will detect and condetion will return true for all virtuemart pages, so for VirtueMart category pages, product pages, or cart pages.

<?php
/* getting value in “Option” variable */
$option = JRequest::getString('option', null);  
?> 
<?php
/* check if it is VirtueMart  page or grabbing  content using  com_virtuemart*/
if ($option == 'com_virtuemart')
{ ?>
  Yes this is a VirtueMart  page and you can place your module or else by replacing   this line
<?php } ?>

CONDITION TO DETECT – IF VIRTUEMART CATEGORY PAGE

<?php 
/* getting value in “view” variable */ 
$view= JRequest::getString('view', null); 
?>

<?php 
/* check if it is VirtueMart  category page*/
if ($view == 'category') 
{ ? >
  Yes this is a VirtueMart  category page and you can place your module or else by replacing this line
<?php } ?>

CONDITION TO DETECT – IF VIRTUEMART PRODUCT OR PRODUCT DETAIL PAGE

<?php 
/* getting  value in “view” variable */
$view = JRequest::getString(view, null);   
?>

<?php 
/* check if  it is VirtueMart product detail page*/
if ($view == 'productdetails') 
{ ? >
  Yes this is a  virtueMart product detail page and you can place your module or else by  replacing this line
<?php } ?>

Add a Comment

Your email address will not be published. Required fields are marked *

ABOUT CODINGACE

My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib

CEO: codingace.com

Request a Quote









PHP Code Snippets Powered By : XYZScripts.com