Adding A Textarea To Virtuemart Products

For some products, or all of your products, on a Virtuemart product, you may want to add a comments or notes section to your products in a Textarea.  There is no easy way to do this but I have come up with one way to do it. Use the following steps to use this method:

  1. Open your addtocart_custom_attribute.tpl.php file with your favorite editor.  This file is found in your components/virtuemart/themes/templates/product_details/includes/ folder. You may want to make a copy of your original file so that you can easily return to the standard file if you do not want to use this change.
  2. Look for the lines that look similar to the following: (this is from line 15 in Virtuemart version 1.1.8).

<input type="text" class="inputboxattrib" id="<?php echo $attribute['titlevar'] ?>_field" size="30" name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>" />

  1. Make changes similar to the following:

<textarea type="text" class="inputboxattrib" rows="5" id="<?php echo $attribute['titlevar'] ?>_field" cols="45" name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>" style="margin-left: 5px; margin-bottom: 10px;"> </textarea>

  1. In Virtuemart, in the product, select the Product Status tab, add your name for the Comment or Note or whatever you want to call it in the Custom Attributes List.

There really isn't much difference to make this work. Now if you want to make this work with multiple types of inputs you will need to make more adjustments to this file with some if or select statements. Let's say you want to have a custom attribute called Burgers that will be a checkbox and every other type of custom attribute is going to be a textarea, you would do something that looks similar to the following:

  1. We are going to add the if statement after the following lines:

foreach( $attribute as $attr => $val )
{
// Using this we make all the variables available in the template
// translated example: $this->set( 'product_name', $product_name );
$this->set( $attr, $val );
}

  1. Add lines similar to the following:

if ($attribute[title]=="Burger")
{
?>
<div style="width: 400px; margin: 0 auto; padding-left :5px;">
<div style='float: left; width: 140px; text-align: right; padding-right: 5px; vertical-align: middle;'><?php echo $attribute['title'] ?>: </div>
<div style='float: left; width: 40px;'>
<input type="checkbox" class="inputboxattrib" id="<?php echo $attribute['titlevar'] ?>_field" size="30" name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>" />
</div>
<?php
}
else
{
?> <div style='float: left; width: 140px; text-align: right; padding-right: 5px;'><?php echo $attribute['title'] ?>: </div>
<div style='float: right; width: 40px;'>
<input type="checkbox" class="inputboxattrib" id="<?php echo $attribute['titlevar'] ?>_field" size="30" name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>" />
</div>
<?php 
}

  1. In Virtuemart, in the product, select the Product Status tab, add your name for the Comment or Note or whatever you want to call it in the Custom Attributes List and also add your Burger. Your Custom Attributes List would look something similar to the following:

Burger; Notes; Comments;

In this example Notes and Comments will be Textarea's and Burger will be a checkbox.


Tags: ,

18 Responses to "Adding A Textarea To Virtuemart Products"

  • Abid says:
  • Reggie Lloyd-Jones says:
  • admin says:
  • alek says:
  • admin says:
  • alek says:
  • Ralph says:
  • Jafu says:
  • admin says:
  • Jafu says:
  • Kath says:
  • admin says:
  • starry says:
  • admin says:
  • Ryan says:
  • admin says:
  • Jafu says:
  • simone says:
Leave a Comment

Spam protection by WP Captcha-Free