Adding Javascript to the WP e-commerce plug in

Lately I’ve been really loving WordPress as more than just blogging software.

Many people need a solution for collaborative website authoring - maybe a combination of static pages and blog posts. They want image galleries, music or video, and other functions and the good news is that WordPress can handle it quite well and still remain easy for people to use. In contrast, as powerful as it is, recent experiences showing non technical folks how to use Drupal (which I really like by the way) - showed me that it was too overwhelming for some users (no flames please - just my experience!).

Anyway… having decided to get a few users up and running with WordPress as a CMS, I decided to look into e-commerce solutions. Because WP is so popular I think we can expect to see more solutions in the future, but for now… there’s not much.

I decided to try out the plug in from from Instinct. This plug in comes in two flavors, free and Gold. I installed version 3.6 RC2 of the free version. At this point, I’m not sure if I will actually use this plug-in but in my limited testing it seemed to work fine. It’s fairly basic - definitely more basic then say OSCommerce but has the advantage that it’s already integrated into WP. In testing, I ran into one small issue which I will discuss here in case anyone else has the same problem and wants a fix.

Problem: I wanted to add JavaScript to the field holding additional product information:

adding JavaScript to a product description

The problem is that this field is processed so that it looks pretty and thus, code breaks.

Solution: I modified the file product_display_functions.php making one small change.

On about line 610 you will find

$output .= nl2br(stripslashes($product['additional_description'])) . “”;

The function nl2br converts newlines to HTML br tags - so we just remove that like so:

$output .= stripslashes($product['additional_description']) . “”;

and that was it.

I can now put JavasScript code into the Additional Description field.

2 Responses to “Adding Javascript to the WP e-commerce plug in”


  1. 1 DavidW

    Hey Paris,
    Nice work. I’ll be adding this to my tools for working with WordPress e-commerce. My own contribution was to write an seo guide for use with this shopping cart and it can be found here http://www.dewpointproductions.com/seo_blog/wordpress/search-engine-optimization-wp-ecommerce/

    Just curious - what will you be doing with it now that you can put javascript in?

  2. 2 parisgraphics

    Hi David,

    Thanks and nice SEO article you’ve got too.
    I’m still not so sure that I’ll really use this module and after looking at all of the e-commerce modules that I can find, I feel like Bono and “Still haven’t found what I’m looking for”. I’m tempted to write my own but have too much other stuff going on. I may just go back to using OSCommerce - but as you know, having everything wrapped up together inside of WP is much nicer for the visitor.
    To be perfectly honest, my reason for wanting to put JS in there was to do something that is offered in the “Gold” version of the module after buying another plug-in for them… that is to embed a music player. The price that they charge for these two upgrades isn’t bad but I didn’t see the point of upgrading when I wasn’t even sure I will use the module.
    My hack works - now I just have to decide if I’ll use it or not.

Leave a Reply