Apr 26, 2015

Ketan Patel

Displaying Custom Product Field on Front End in Opencart

In my one of previous tutorial we learned about "Adding Custom Product Field in Opencart".This tutorial will explain how to display the custom product field on front end. 

Note: Before making any changes directly at any levels , its recommended to take a Backup of database and files.

All the changes explained in this tutorial is for the default theme and English language. If you are using custom theme then some extra changes are required.If you're running a store in multi language , then you need to download the respective language pack from the opencart extension store and need to add the changes in that pack also.


So before starting, we need to list out the pages where we need to display the custom product field on front end. Below are some of the pages at front end in which we are going to make the changes to display the custom product field.


  1. Product Detail page
  2. Products Compare Page
  3. Products Search Page



Product Detail Page


As the name suggests, Product detail page has all the information about the product. If you want to display the custom_desc field then make the following changes:

(1) Open catalog/language/english/product/product.php file and add the below line :

$_['text_custom_desc']         = 'Custom Description:';

(2) Open catalog/model/catalog/product.php file and search for the below code in the getProduct() function:

'isbn'             => $query->row['isbn'],

and add the below code just after that :

'custom_desc'      => $query->row['custom_desc'],

(3) Open catalog/controller/product/product.php file and search for the below code:

$data['text_loading'] = $this->language->get('text_loading');

and add the below line just after that:

$data['text_custom_desc'] = $this->language->get('text_custom_desc');

Now search for the below line:

$data['entry_bad'] = $this->language->get('entry_bad');

and add the below line just after that:

$data['entry_custom_desc'] = $this->language->get('entry_custom_desc');

Search for the below line :

$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');

In case if you use ckeditor for adding new "custom_desc" value in the admin side, then add the following code just after that.

$data['custom_desc'] = html_entity_decode($product_info['custom_desc'], ENT_QUOTES, 'UTF-8');

otherwise you can simply add as below,

$data['custom_desc'] = $product_info['custom_desc'];

Now search for the below line:

'special'     => $special,

and add the below code just after that:

'custom_desc' => $result['custom_desc'],

(4) Open catalog/view/theme/default/template/product/product.tpl file. Now here we have more that one choices.

-- If you want to display the custom_desc inside the description tab, then find the below line

<div class="tab-pane active" id="tab-description"><?php echo $description; ?>

and add the following code just after that (inside the same div).

<?php echo $custom_desc;?>

-- If you want to display the custom_desc just after the product title, then find the below line:

<h1><?php echo $heading_title; ?></h1>

and add the below line just after that:

<?php echo $text_custom_desc; ?> <?php echo $custom_desc;?>

-- If you want to display the custom_desc in the Related Products block , then search for the below line :

<p><?php echo $product['description']; ?></p>

and add this just after that:

<p><?php echo $product['custom_desc']; ?></p>


Products Search Page


Opencart provides the searching functionality to easily find the product the user want to search in the store. If you want to display the custom_desc field display in the search page then do the following changes:


(1) Open catalog/controller/product/search.php file and search for the below line in the $data['products'][] array:

'price'      => $price,

and add the below line just after that:

'custom_desc' => $result['custom_desc'],


(2) Open catalog/view/theme/default/template/product/search.tpl file and search for the below line :

<p><?php echo $product['description']; ?></p>

and add the below line after that :

<p><?php echo $product['custom_desc']; ?></p>



Product Compare Page


Opencart provides the functionality of comparison between the products so that users can view the features of the different products side by side. In order to add the custom_desc field in the product compare page make the below changes.


(1) Open catalog/language/english/product/compare.php file and add the below code:

$_['text_custom_desc']  = 'Custom Description';


(2) Open catalog/controller/product/compare.php file and find the below code:

'model'        => $product_info['model'],

and add the below line of code just after that:

'custom_desc'  => $product_info['custom_desc'],

Now find,

$data['text_summary'] = $this->language->get('text_summary');

and add the below code just after that:

$data['text_custom_desc'] = $this->language->get('text_custom_desc');


(3) Open catalog/view/theme/default/template/product/compare.tpl file and search for the below code:

<tr>
    <td><?php echo $text_summary; ?></td>
    <?php foreach ($products as $product) { ?>
    <td class="description"><?php echo $products[$product['product_id']]['description']; ?></td>
    <?php } ?>
</tr>

and add the below code just after that:

<tr>
    <td><?php echo $text_custom_desc; ?></td>
    <?php foreach ($products as $product) { ?>
    <td class="description"><?php echo $products[$product['product_id']]['custom_desc']; ?></td>
    <?php } ?>
</tr>


That's it..!! You have custom_desc field display in front end. Let me know if you get any error , issues or want to display custom_desc in any other section of the front end side. I will add the code for the same as an update of this article.




Ketan Patel

About Ketan Patel -

I have developed a wide range of websites using CorePHP, Opencart, CakePHP and CodeIgniter including sites for startup companies and small businesses. Apart from my blogging life, I like to read Novels, Listening music and Net surfing.

Subscribe to this Blog via Email :