Lee Willis

April 9, 2010
by Lee
328 Comments

Region-based shipping with WP e-Commerce

I’ve been asked a few times about how to split up countries into regions and charge shipping differently to the different areas in WP E-Commerce. This was something that was almost, but not quite possible with one of my existing plugins.

Now it’s just a little bit easier.

What You’ll Need

In this example we’re going to show how to achieve the following:

  • Set of Weight rates for New Zealand (North Island)
  • Set of Weight rates for New Zealand (South Island)
  • Set of Weight rates for the rest of Asia/Pacific
  • Set of Weight rates for Europe

The Plan

To acheive our end goal we’re going to:

  1. Create 2 regions attached to the country “New Zealand”
  2. Remove New Zealand from the Asia and Pacific continent (So people ordering to NZ see those prices, not the general “Asia and Pacific” pricing
  3. Set up per-country/region rates for New Zealand
  4. Set up per-continent rates for Asia and Pacific, and Europe

Getting Started

The first job is to find out the “country ID” for New Zealand. Using your favourite database you’ll want to look in the wp_wpsc_currency_list table for the entry for New Zealand, and make a note of the value of the “id” field – in our case 156.

While we’re here, we’ll also move New Zealand out of it’s current continent. This basically just involves updating the same record, and setting the continent field to something unique, e.g.

Next – you’ll need to create whatever regions you want in the wp_wpsc_region_tax table, using the ID you’ve just found as the “country_id” field, e.g.

Configuring your pricing

That’s all with the scary database stuff, now on to the easy stuff. First of all you’ll need to activate both of the shipping modules:

First up we’ll configure the continent-based pricing. Click on “Edit” next to the weight-continent pricing. Up will pop the configuration pane, with a drop-down of the standard continents – and also our “newzealand” continent – which we’re not going to use since New Zealand is going to be priced by region.

Let’s pick Europe, and configure some weight rates.

In this case we’ve just configured one weight band – which means that anything shipped to Europe will be charged at the same rate – £80 in this case.

We can do the same for Asia and Pacific, except maybe setting up multiple layers using the “Add Layer” link.

At this stage shipping will work for Europe, Asia and Pacific, but not for New Zealand (Since we took it out of Asia and Pacific).

Click on “Edit” next to the Weight / Country and Region pricing. Up will pop the configuration pane, with a drop-down of the countries, including regions where configured – for example, we can see our North Island, and South Island regions here:

Selecting a region gives us the chance to configure weight rates, e.g.

Repeat for other regions, and you’re set. Happy Shipping!

Note: All weights should be set up in lbs, no matter what weight unit you used to set the weight for your products. WP e-Commerce will convert between them for you.

March 6, 2010
by Lee
0 comments

WordPress 2.9 e-Commerce

WordPress 2.9 E-Commerce WordPress 2.9 e-Commerce, has been published – the definitive guide to setting up an e-commerce site on your WordPress blog using the WP e-Commerce plugin, of which I’m a bit of a fan.

This book provides an easy to understand, step-by-step approach to installing, configuring, and using WP e-Commerce to run your online store. We will construct an example store in the book with enough information and flexibility to adapt the store to your specific needs.

This book is for you, if you are interested in using WordPress as the basis for a store that can sell physical items, downloads, or services. It is ideal for a sole proprietor or small business owner with only basic, in-house technical skills. Some prior knowledge of WordPress will help, but is not required. No knowledge of PHP is expected, but it will be helpful.

You can buy it from Amazon here.

Disclaimer: I’ve linked to Amazon using affiliate links, to help fund this blog.

January 29, 2010
by Lee
39 Comments

Getting URL of Post Thumbnails in WordPress 2.9

One of the improvements in WordPress 2.9 is native support for thumbnail images on posts. The API is pretty good – although it assumes that you want to return the whole IMG tag. In my case I wanted to return the URL of the image (So I could wrap the actual thumbnail in a lightbox-style link to the larger versions).

So – if you want to get the URL of your posts thumbnail – here’s the code you need:

$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];

I hope this helps you with your theme development.

October 17, 2009
by Lee
103 Comments

How to Split Test WordPress Themes

I recently re-worked a site for a client. He was moving over from Joomla to WordPress, so I started from scratch with his theme design. They liked the new theme I came up with – however I’d put the menu and other navigation (Links to recent articles, etc) in a right hand sidebar, and they weren’t too sure about that.

“Doesn’t everyone have the menu on the left?”

Now I’m no usability expert, and while I figured they were probably right I thought we’d run a little experiment. I trawled around a bit, and I found a nice little post by David Dellanave. While I was OK implementing David’s solution I though it was probably a little complicated for some of my other clients, especially when it came to running 3 Google analytics accounts – so I did some digging.

The result is the SES Split Testing plugin.

To use the plugin you’ll need to be using Google Analytics tracking on your WordPress blog already (If you’re not, then I’d recommend the “Google Analytics for WordPress” plugin), then :

  • Create two (or more) versions of your theme
  • Select them in the plugin settings
  • Define custom segments in Google Analytics
  • Sit back and watch the results roll in

Create theme variations

In most cases, you’ll want to test two versions of 1 theme with some slight changes. Let’s assume your theme is in the folder wp-content/themes/mytheme. Take a copy of your theme and put it in fresh folder, e.g. wp-content/themes/mytheme_2. Open up the style.css file in the second folder, and change the Theme Name, e.g.

/*
Theme Name: MyTheme
*/

to

/*
Theme Name: MyTheme (v2)
*/

Set up plugin settings

Wordpress Theme Split TestingNow you can drop the plugin into your plugin directory, activate it in the WordPress backend, and then go to the settings page (Settings->SES Theme Split Test). The plugin will list all of your available themes, and you can choose which ones you want to be part of the test.

Once you’ve saved the settings, the split testing will kick in. Visitors will be randomly assigned one of the chosen themes, and they’ll receive that theme any time they visit in the next 30 days. Not only that, but their visit will be tagged with a special variable that you can pick up on in Google Analytics.

Set up Custom Analytics Segments

Google Analytics lets you define custom segments (Ways of grouping customers). In this example we want to group customers according to which theme they were shown and then we can measure our chosen metric (Purchase / sign-up / page views – whatever) for the two groups and compare them. To get started, you probably want to wait 24 hours so that Google starts to receive the tagging data.

Setting up custom segmentsLog into your analytics account, and click on the “All Visits” dropdown (Top-right, just above the date selector), and then choose “Create a new advanced segment”. Then, you want to expand the “Visitors” dropdown under “Dimensions”

Custom Segment Build

Scroll down until you find “User Defined Value” and drag it onto the right hand box that says “dimension or metric”. If Analytics has got your tagging data (See – I told you to leave it 24 hours!) then you’ll get to choose from the values being passed, e.g.

Analytics Custom Segments

Create a segment for each of your themes, and give them a meaningful name, then you’ll be able to select them as custom segments in your reports.

Segmented Analytics Reports

Now it’s just time to wait, see what happens, then decide. Once you’ve got a winner then just set that as your blog’s standard theme in the normal way, and either deactivate the plugin, or unselect the themes in the settings and users will see the blog default.

September 25, 2009
by Lee
0 comments

Google edges towards local hubs

Google has announced the launch of “Place Pages”. Essentially a local hub showing you relevant information from maps, search, business listings and so on.

It’s a fairly basic implementation right now (My local page doesn’t return any info just yet – not even businesses that I know are listed with Google) – but you can see that these could develop into fairly complex local hubs if Google feel that it helps relevance. Not to mention the potential for locally-targetted ads …

Is your place listed?

September 18, 2009
by Lee
1 Comment

A/B Testing Your Email Marketing

I’ve been working with a few clients to move their email marketing to a new home after most of them outgrew the limits of what they could reliably send through their existing infrastructure / hosts. Now – marketing isn’t really my strong point, and I’m definitely no designer – however I recommended and helped move over a number of campaigns to Campaign Monitor (The other key contenders appear to be MailChimp and Constant Contact).

Campaign Monitor appealed to me because of their clear, easy to understand website, and their fantastic interactive tool for creating mailings and because they generally seemed to be a good company.

Yesterday, they rolled out a new feature, conveniently coinciding with me sending a mailing out for one of my clients. A/B Testing is something I’ve done before with web content, but never with email campaigns, so I was intrigued to find out how it would work (I was dreading segmenting my mailing list and so on …)

A/B Split Type

The good news is, that it’s really simple. You can choose to run different Subject lines, Email Content, or From addresses.

In my case, the functionality arrived a little late for me to create 2 designs (I’m not a designer, and even making basic changes tends to take me a while!), so I plumped for the Subject Line test.

I chose my two subject lines, picked the subscriber list it was to go to (In this case it was actually a fairly small list – around 45 recipients only) and moved to the next step.

Next, I had to decide how I would pick my winner, and how many of my total list would constitute “the test”

Choosing a winner

Now here came my first problem – the default that campaign monitor chose for my “test” was just two recipients, one would receive option A, and one more would receive option B. The idea then is that based on the reaction (Which got opened more, which got the most clicks overall, which got the most clicks on a specific link) the winning version will go to the rest of the list. Now – even if I ran the test on the whole of the 45 recipients it probably wouldn’t be a statistically valid test. Certainly, I think Campaign monitor should have a higher “lower limit” on how many it suggests as the sample size.

Anyway – I upped the test size (I went for five recipients for each version which I agree isn’t ideal, but I was really just seeing how the functionality worked – this wasn’t a huge marketing exercise!)

Off the test went – I set it to run for 3 hours. There came my next problem. It became a bit apparent that I really should have chosen a bigger sample size in order to get a sensible response. Unfortunately by this stage “the test” is locked – you can’t extend it to more people – or extend the time before a winner is chosen.

I’m sure there’s probably some clear guidelines about why you shouldn’t do that sort of thing anyway (It probably invalidates the whole test, or makes hurricanes in Bolivia or something …), but it struck me that it wouldn’t have been nice to have done it anyway! I’ll certainly be using the feature on my next larger scale campaigns.

Note: MailChimp also appears to support split A/B testing of campaigns in a similar fashion – I couldn’t tell whether Constact does or doesn’t.

September 7, 2009
by Lee
3 Comments

How to write an application for WordPress

I’ve recently been doing some work for a family member on a WordPress blog they run, and the need came up to build a mini-app. Now historically, I’m a Joomla kind of guy, and it’s fairly clear that for a Joomla site you would build a component to implement your app.

However, in WordPress it’s a little different. I’ve found loads of articles about available API calls, manipulating “the loop” and all sorts of useful information. What I haven’t found though is something that explains at a fundamental level how I should approach the problem.

There isn’t a concept of an “application” under WordPress, the only items that are accessible are “posts” and “pages”. As far as I can tell, I have two options:

  1. Publish a post/page with no content other than a special string (E.g. [my-app]) and then write a plugin that filters post content and replaces the magic string with the output from the application
  2. Create a page, and assign it a custom template. Implement your application in that custom template

Option 1

It works, I know because this is what I did :)    However there is a performance penalty, your application code is called on every post, and so you have to take steps to make sure it doesn’t run unnecessarily. The other disadvantage is that well, it just doesn’t seem clean.

Option 2

This seems a little nicer, but doesn’t really fit with WordPress’ nice plugin installation architecture – as far as I can tell plugins can’t auto-install into the current theme directory, and custom templates can’t live anywhere else.

So, this leaves me a little confused – can anyone point me as to how I should have solved this problem – or does WordPress need to grow up a little and add “application” alongside posts and pages?

August 7, 2009
by Lee
2 Comments

Tracking Twitter Traffic Redux

I wrote a previous post about how you could hack the excellent Twitter Tools plugin from Alex King to add Google Analytics tracking variables to the URLs posted to twitter when you posted a new blog post.

I submitted the patch upstream, and Alex kindly pointed out that rather than bodging around in his code – you could achieve the same effect with a filter.

So, here it is. Simply download this file and save it in your wp-content/plugins directory. Activate the plugin in your WordPress backend (It will be listed as “Twitter Tools Tagger”) and away you go. Whenever the twitter-tools plugin tweets about one of your blog posts, the URL will be tagged with analytics tracking.

As an added bonus, version 2.0 of Alex’s plugin can also pump your URLs through the http://bit.ly/ URL shortening service so your URLs will be tagged, and shortened.

So, that’s nice.

August 7, 2009
by Lee
9 Comments

Custom Taxonomies In WordPress Plugins

Taxonomy Support

I wrote recently about building a brand directory using a fantastic feature of WordPress called “Taxonomies”. Now that that feature is live I’ve realised that a number of my favourite WordPress plugins simply don’t support taxonomies.

Among the casualities were Google XML Sitemaps, and the otherwise excellent Headspace2.

Now, the beauty of open source is that when you get an itch like this, you can go and scratch it. So, I whipped out my coding gloves and set to work.

The results are below:

Google XML Sitemaps

The patch below will ensure that the pages for all of your taxonomy terms are listed in your sitemap – helping Google find the pages quicker.

http://www.leewillis.co.uk/patches/google-sitemap-generator/include_taxonomies.txt

HeadSpace2

The patch below lets you add %%term_description%% so you can populate your META tags properly on your term pages – great for us and our product directory.

http://www.leewillis.co.uk/patches/taxonomy_support_for_headspace/patch_v2.diff

Both of these have been submitted to the plugin authors – so hopefully they’ll get included by default in a future release. If you find them useful – please add to the threads here:

Google XML Sitemaps

Headspace2

July 31, 2009
by Lee
43 Comments

Using WordPress taxonomies to create a product directory

Background

WordPress lets you categorise your posts according to “tag”, and “category”. Which is fine. However, for some time now WordPress has supported a concept called “Custom Taxonomies”. Which is a long winded way of saying “We’ll let you choose how your organise and present your posts – however you want”.

This isn’t something I’ve ever felt the need to use before (I’m happy enough with tags on this blog) – however having used them recently I’ve really begun to appreciate how powerful they are – and I’m amazed that more people don’t use them to create a more sensible structure to their WordPress sites.

That said, I’m a bit of a geek, who’s not averse to diving into code, and isn’t intimidated by a set of cryptic API documentation :)

The Business Case

So, what can taxonomies do for you?

The site I built this for is a resource all about baby slings, the different types, the different brands, and people’s experiences, of finding, choosing, and using them.

Tagging just seemed to create a big, hard-to-navigate tag cloud that didn’t create an easy way for people to find the right content on the site that was going to be useful to them (Feedback has suggested that people are either looking for information about a particular brand, or a specific type of sling irrespective of brand).

The How-To

So, out went the “tags” (We removed them from most old posts, don’t add them to new posts, and got rid of the “tag-cloud”). Next step was to install Joost de Valk’s Simple Taxonomies plugin. This is one of Joost’s simpler plugins. In general all it does is let you create a taxonomy, and manage the terms within that taxonomy.

Actually, as an aside – I suspect this is why custom taxonomies haven’t really taken off. Out-of-the-box you have to create code to set them up and use them for effective site navigation. If the functionality provided by Joost’s plugin was in WordPress core, and theme authors really started coding for this stuff, I’m sure it would fly, but I digress …

So, using the plugin, we created two taxonomies – “Brands”, and “Sling Types”.

Taxonomy Settings

Next step was to go back through our posts (Fortunately this was in the early days of the site!), and correctly “tag” the posts against the right taxonomies. So on the SnugBaby review, we set the “Brands” to “SnugBaby”, and the “Sling Types” to “Mei Tai”.

Tagging Taxonomies

Now we’ve got all of our posts beautifully organised, but we don’t have a way to view them. Before we get to that though, there’s just one more step. For every “term” (ie, for every brand, or sling type) we need to provide a description. Your new taxonomies can be found in the “Posts” section of the WordPress backend, simply click on the taxonomy, e.g. “Brands”, then work your way down the list adding a useful description.
Taxonomy Descriptions

Now we can actually start presenting this information sensibly!

Theme Work

Now, we’re going to use that list of “terms”, and their descriptions, to create a top-level list of “brands”. Download the file below, and save it in your WordPress theme directory. We called it “brand-directory.php”, but the name doesn’t really matter.

brand-directory.php

This will create a new page template called “Brand Directory” (If you want to change the name, edit the comment at the top of the file).  Now create a page in WordPress, provide some content that you’d like to use as an introduction, and set the page template to this new file:

Set Page Template

Basically all this file does is display the page content you created:

<?php the_content(); ?></p>

followed by each one of the terms that you’ve used, along with it’s description:

$terms = get_terms(‘brands’);

foreach ($terms as $term) {

echo $term->description;

and a link to all of the posts that have been assigned to that term:

$wpq = array (‘taxonomy’=>’brands’, ‘term’=>$term->slug);
$query = new WP_Query ($wpq);
$article_count = $query->post_count;

if ($article_count) {
echo “<a class=\”taxonomy-rel-link clearfix\” href=\”/brands/”.$term->slug.”\”>”.$article_count;
} else {
echo “<span class=\”taxonomy-rel-link\”>$article_count”;
}

echo ” related article”;
if ($article_count!= 1) echo “s”; else echo  “”;
if ($article_count>0) {
echo ” – click to view</a>”;
} else {
echo “</span>”;
}
echo “<br />”;;

And there you have it, a dynamic data driven directory that keeps itself up to date whenever you “tag” a brand – all you have to do is add a description for the brand!

For an example see the “Get Your Hands Back!” brand directory here.