Nicolasbottari.com

How to fix some Wordpress e-commerce plugin annoyances


Here are some small fixes I found during Wordpress site development using the WP e-commerce plugin. Although the plugin is a quick (and free!) way to quickly put up a small e-commerce section on a website, it still requires a handful of improvement to make setup more simple to use.

Removing decimals to prices

This should be an option in the control panel, but unfortunately isn't. Not every currency has decimals (eg. Japanese yen), so the extra ".00" needs to be dropped. This can be done by first setting the plugin not to display decimals in the control panel. Unfortunately, this setting does not extend everywhere, so two files need to be modified:

In the wp-e-commerce/wpsc-includes/cart.class.php file near line 1362, change

$price = numberformat($price, 2, '.', ','); 

to

$price = numberformat($price, 0, '.', ',');

 

In the wp-e-commerce/wpsc-includes/processing.functions.php file near line 81, change

$priceout = numberformat($pricein, 2, '.', ',');

to

$priceout = numberformat($pricein, 0, '.', ',');

Use form-submitted values in confirmation email/thank you page

Another feature that should be working out-of-the-box. By default, only the following tokens can be used in emails and thank you pages (Store > Settings > Admin): %shopname%, %productlist%, %totalprice%, %totalshipping%, %findus%. How about the client name? Or email address? Or shipping info? Would be nice to have a "Thank you, Mr. X, for your order", right?

Not the best type of hack, but works. Each input field you set up in the wp e-commerce control panel has an field ID attached to it. Let's get those IDs and create new tokens like %fieldid1%. In the wp-e-commerce/transactionresultfunctions.php file, add the following near lines 231 (or anywhere in that area):

$submittedformdata = $wpdb->getresults('SELECT * FROM wpwpscsubmitedformdata WHERE log_id="'.$purchaselog['id'].'"');
foreach($submittedformdata as $k => $v) {
   $extrafielddata[$v->formid] = $v->value;
}

foreach($extrafielddata as $id => $value) {
   $message = strreplace( '%fieldid'.$id.'%', $value, $message );
   $report = strreplace( '%fieldid'.$id.'%', $value, $report );
   $messagehtml = strreplace( '%fieldid'.$id.'%', $value, $messagehtml );
}

You should now be able to add %fieldisX% tokens (X being the field ID) in the report and client message emails, as well as the shop HTML pages.

Multibyte shop category names

Looks like multibyte characters do not play nice with category names in the WP e-commerce plugin. By default, the category name is used to create the "nice-name" which can be thought of as the category slug. With multibyte characters (eg. Japanese), this can become a problem when used in URLs. If you do not use the category description field, that field can be used to store your multibyte name, and the category name is used for your standard alphanumeric category name. To do this, a small change is needed in the wp-e-commerce/wpsc-includes/category.functions.php file at lines 29-31. Change:

function wpscprintcategoryname() {
    echo "[wpsccategoryname]";
}

to

function wpscprintcategoryname() {
    echo "[wpsccategory_description]";
}

Your multibyte text will show on the site, but your URLs will contain alphanumeric characters based on your category name field in the control panel.

Hopefully this can come in handy for someone. And yes, using ExpressionEngine with Freeform might have been faster.