Search By SKU In Woocommerce

If you would like your customers to be able to search by your product SKU field in Woocommerce then simply add this code to your theme’s functions.php file.

/* Add sku to product search */
function search_by_sku( $search, $query_vars ) {
    global $wpdb;
    if(isset($query_vars->query['s']) && !empty($query_vars->query['s'])){
        $args = array(
            'posts_per_page'  => -1,
            'post_type'       => 'product',
            'meta_query' => array(
                    'key' => '_sku',
                    'value' => $query_vars->query['s'],
                    'compare' => 'LIKE'
        $posts = get_posts($args);
        if(empty($posts)) return $search;
        $get_post_ids = array();
        foreach($posts as $post){
            $get_post_ids[] = $post->ID;
        if(sizeof( $get_post_ids ) > 0 ) {
                $search = str_replace( 'AND (((', "AND ((({$wpdb->posts}.ID IN (" . implode( ',', $get_post_ids ) . ")) OR (", $search);
    return $search;
add_filter( 'posts_search', 'search_by_sku', 999, 2 );

Tested in Woocommerce 5.

A little side project…

I’ve been busy recently designing a series of mugs with quotes on for sale on my Etsy store. The mugs feature quotes from some of my favourite books, TV shows and movies and they are an interesting exercise in product design and typography. Some of the designs are quite basic at the moment but I’m learning what’s possible, what looks good and what people like.

The Big Painting Challenge – Why So Challenging?

I’ll come clean up front and state I haven’t seen the whole series of BBC’s The Big Painting Challenge 2017, a competition for amateur artists using a similar format to The Big Pottery Throwdown, The Great British Sewing Bee and of course the collosal hit The Great British Bake Off.

The show describes itself like this:

Passionate amateur artists undertake an intensive, six-week, artistic boot camp in a bid to perfect their skills and be crowned the overall champion.

I’ve only seen a few bits and pieces of The Big Painting Challenge until last night when I saw the fifth episode, Movement. This episode’s challenge was for the artists to convey proportion and movement in their work whilst observing ballerinas in action.

The show had me almost incandescent with rage at several points. I have a BA Hons in Illustration and have studied Fine Art and Art History over the years and spent many, many hours drawing life models in many situations, including drawing during a theatre performance of Chekov’s The Cherry Orchard from the stalls and painting horse racing during a race meeting as part of my illustration degree course. Our artists seemed completely lost as the ballerina performed her routine whilst the artists looked on agape and gasping “How are we going to paint this?” Surely lesson one in this “artistic boot camp” would have involved some sort of rapid sketching exercises to loosen the artists up? But I guess that’s not good telly. In fact I was so curious as to the contents of lesson one that I watched episode 1 on iPlayer and found that lesson one was a still life and Pascal described his teaching style as “alternative thinking.”

Needless to say I was spitting “Fuck you”‘s at Pascal, one of the mentors, as he denegrated the eventual heat winner’s charcoal drawing of the ballerina shown in the clip above as “my worry here is that it’s going to be an illustration. Don’t be afraid of your response as an artist to what’s here.” What the fucking fuck does that even mean? Why use illustration as some kind of dirty word? Why assume that because something is well observed, well drawn and executed that it’s not showing some kind of emotional response from the artist? Does he think that because illustrations are usually done as work for hire that this somehow makes the art less valuable? Most of the work by the greatest artists in history were commissions from wealthy patrons or institutions (usually the Catholic Church) and the techniques used in these pieces inform and influence the techniques and styles used to this day. Edgar Degas, who is mentioned in this episode, was famed for his paintings of ballet dancers but Degas’ later works were all painted to generate an income for himself as he had spent all his money and sold his art collection to pay off his brother’s business debts. Does this somehow lessen the emotion Degas imbued in his work? Of course not. Does the work of William Blake generate less emotion because he was an illustrator? Was he not creating the work for himself as well as an audience? Is that not precisely what the contestants in this show are doing? I’m sure that painting dancing ballerinas would not be on any of their lists of future projects unless the Beeb were making them do it.

Edgar Degas - Two dancers on a stage c.1874

Edgar Degas – Two dancers on a stage c.1874

Oberon, Titania and Puck with Fairies Dancing circa 1786 William Blake 1757-1827 Presented by Alfred A. de Pass in memory of his wife Ethel 1910

From the BBC’s description above one would assume these amateur artists had at least been taught some basic techniques over the previous 4 weeks about observation and sketching. Pascal again attracted my wrath as he tried to get his 2 students to paint 100 moving figures on a busy London street using 1 stroke of a brush per figure. How about teaching them some basics? How about a quick lesson in proportions considering that’s what your students will be critiqued on? No, they just stood in the strret drawing lines with a brush.

During the final challenge of this episode the artists had to create a piece of artwork based on a live performance of Swan Lake that was performed several times for them. The ballerinas entered the room, performed and left and I was dismayed to see that not one of the artists was taking the time to sketch the ballerinas in action whilst they were in the room. The artists were not making preparatory sketches and the artists’ “mentors” were intent on getting the artists to paint their “observations” immediately and spend no time studying the figures in motion, preparing sketches, planning composition or working on proportions. Of course, as the artists worked these “mentors” subsequently ripped the artwork to pieces, complaining about lack of motion, poor composition and poor proportions. Proper Planning Prevents Piss Poor Performance as the saying goes!

The artists final pieces were then judged by the usual motley crew of reality show judges and their feedback was generally fair and reflected more on the quality of their teachers than on the artists themselves.

10 Essential WordPress Plugins

iThemes Security

iThemes Security is my number 1 pick for securing a WordPress site. Not only does the handy wizard walk you through the process of securing your site against bots, hackers and malware but it also includes a backup facility to back your entire site up. The backup file is then saved to the local file system or sent to an email address of your choice.

SEO Ultimate

SEO Ultimate is a recent discovery for me. For years I have used WordPress SEO by Yoast which is a fine plugin but lacks a few features that SEO Ultimate does have. SEO Ultimate’s Deeplink Juggernaut is especially useful on large sites as it gives you the ability to link any anchor phrase on any page straight to your desired target page without having to manually edit every page individually. There’s also a code inserter so you can automatically add code to the header and footer and before or after each article on your site. The 404 monitor also shows you what pages are being hit on your site and causing 404 errors so you can address those. It really is the ultimate SEO toolkit for WordPress.

Contact Form 7

Contact Form 7 makes making contact form a breeze. The plugin supports all possible combinations of form elements allowing  you to create complex data capture forms very simply. You can even make the elements accessible for impaired users as required by EU regulations.

Black Studio TinyMCE Widget

Black Studio TinyMCE Widget is one of my favourite widgets. This handy little plugin allows you to add a widget in any sidebar that has the WordPress wysiwyg editor enabled for easy editing of your widget’s content. No more inserting HTML codes by hand in your widgets!

TinyMCE Advanced

The TinyMCE Advanced plugin unlocks the full power of the WordPress visual editor, which is a cut down version of Moxiecode’s TinyMCE wysiwyg editor. TinyMCE Advanced allows you to define your own toolset for the visual editor window. Want to add an easy table creation tool? Done! Want to add font control to the editor? Done! Just drag and drop your required features on to the toolbar and save.


Autoptimize shrinks your HTML code, CSS and Javascript files so they load faster. Many other plugins promise this facility but this is the only plugin I’ve found that works 100% of the time and does not break a site in the process.

EWWW Image Optimizer

EWWW Image Optimizer is a free alternative to Smush.It and does everything Smush.It does including bulk lossless optimization of media files and other images outside of the uploads folder.

Velvet Blues Update URLs

I use Velvet Blues Update URLs on almost every WordPress site I build. If you build a site on a development server like I do then roll the site out on to a live server you may see that some of the live site’s content still links to the development server. Oh dear. Velvet Blues Update URLs will scan your content and links for the URL you input and replace it with another URL of your choice so you don’t have to edit every single page, image or link manually.

Google Analytics by Yoast

Google Analytics by Yoast is quite simply the best plugin I have found to add Google Analytics tracking codes to your site. The plugin is regularly updated so you can be sure you have the latest tracking codes on your site, add reports and see helpful GA dashboards in your WordPress dashboard.

Easy Bootstrap Shortcode

If you’ve ever built a WordPress theme with Bootstrap and want your clients to be able to add columns and the other goodies that Bootstrap brings to your site then you’ll need the Easy Bootstrap Shortcode plugin. The plugin adds a menu of shortcodes to your WordPress visual editor which makes adding Boostrap enabled content to your site as easy as 1-2-3.

What plugins are in your essentials list and why? Let us know in the comments section below.

How To Set Up Google Content Experiments in Magento 1.7

I spent a lot of time looking around for a way to conduct Google Analytics Content Experiments in Magento with very little success. I did find this post in Finnish that detailed one approach and I adapted his findings (with the help of Google Translate) in to the following solution.

Step 1 – Set up your Content Experiment code block
In CMS > Static Blocks add a new static block with an easy to identify name such as “Google Content Experiments Code” and an identifier such as “google_code_block”. Paste the Content Experiments code in to the wysiwyg editor by pressing the HTML button and pasting the code in to the pop up window. Click “update” and the window will close but you won’t see anything appear in the wysiwyg window. This is normal.Make sure you enable the code block and save it.

Step 2 – Alter your template to write the code block
In your appdesignfrontenddefaultyourtemplatetemplatepagehtmlhead.phtml file add the following code right at the top after meta charset="UTF-8"

<?php  $routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo $this->getLayout()->createBlock('cms/block')->setBlockId('google_code_block')->toHtml();
} else {

If you are performing an experiment on a page other the home page you will need to change the $identifier string to match your page identifier which is your URL key. You will also need to change the Block ID if you have called your code block something different.

Step 3 – Disable the code block on your variation pages
Set up the variations of your CMS page and in the Layout Update XML part of the Design tab paste the following XML code:
<reference name="head">
<remove name="google_code" />

This will stop the code block from loading on the variation pages as per Google’s instructions.

Step 4 – Verify it all works in Google Analytics!
Check it all works in GA and start your experiment.

I’ve yet to work out a way to perform experiments on category pages without creating a brand new category containing the same products.