Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Adding Boilerplate text to the Product Description in osCommerce


Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: osCommerce 2.2rc2a and forward. The same approach can be used in prior versions.

Related: Using Files Containing Boilerplate Text in the Product Description


To save typing repetitive text in the product description field, and to facilitate easier mass changes of boilerplate text, it is advantageous to use PHP variables defined in a single place. However, osCommerce itself does not support the use of PHP within the description field.

Here's how to add it yourself.

You will be defining your boilerplate strings in a file called
catalog/includes/languages/english/my_defines.php
Each string will have a PHP "key" which will be used in the description area in admin, and a longer "value" which is the actual boilerplate text to be displayed. In this way, users can simply add and delete strings by editing this one file, rather than having to dig into the internals of osCommerce.

We'll use a simple example:
<?php
$stringArray = array ( 
   '%%ONE_WEEK_DELAY%%' =>  '<br />These decals will be shipped in one week after receiving your order.',
   '%%TWO_WEEK_DELAY%%' =>  '<br />These decals will be shipped in two weeks after receiving your order.',
   '%%THREE_WEEK_DELAY%%' =>  '<br />These decals will be shipped in three weeks after receiving your order.',
); 

?>

We've defined three strings.

Now go to
catalog/product_info.php
Change
  <p><?php echo stripslashes($product_info['products_description']); ?></p>
to
<?php 
$stripped_products_description = $product_info['products_description'];
require(DIR_WS_LANGUAGES . $language . '/my_defines.php'); 
foreach ($stringArray as $key => $value) { 
   $stripped_products_description = str_replace($key, $value, $stripped_products_description);
}
echo '<p>' . stripslashes($stripped_products_description) . '</p>';
?>

Now to use this logic, all you need to do is type %%ONE_WEEK_DELAY%% in your product description (under Admin - Catalog - Categories and Products), and when you display the product info page, it will be changed.

If you display the Description in any of the other lists (Category Listings, Search Results, Manufacturers), you will need to modify their description display code in the same way.