The Blog

Setting a custom, category specific, product sort order in WooCommerce using Advanced Custom Fields

If you run your online shop using the excellent woocommerce plugin, built on top of the wordpress platform, and you want to set a custom (category specific) sort order for your products, sadly you are out of luck. The built in ‘sort products’ function works well if you dont mind having a global product sort order which remains the same across all categories, but if you want to have more fine-grained control over your sort order you need a little something extra. Having recently encountered this exact problem whilst working on some customisations for a client, and after 30 minutes of fruitless searching to find a pre-rolled solution, I thought it was time to roll up my sleeves instead. Some requirements for our solution;

  • It has to be ‘clean’ and not require changes to core files or the templates themselves to align with our coding practices.
  • It has to be executed in a way where we can enable/disable it and test it easily.
  • It has to be simple enough for the client to understand without needing any special training.
  • It has to allow custom ordering, but allow for any products which aren’t included to still appear in the category (after the ordered ones)

I am assuming that you already have WordPress and WooCommerce installed and are know your way around your active theme (or at the very least can edit functions.php within your theme directory), and have commented the code to explain what each part does;

Here are the steps involved to achieve custom product wort order nirvana;

  1. Download and install the excellent Advanced Custom Fields plugin
  2. Create a field group called something like ‘product order’ containing a single relationship field (can also be called ‘product order’). Fortunately the relationship field lets you drag and drop your objects in the order you want them, and will return an array of IDs in the order you set in the edit screen. Handy!
  3. Set ‘Filter by Post Type’ to ‘Product’
  4. Set ‘Return Format’ to return Post IDs
  5. Add a custom rule to your custom fields group to only appear if “Taxonomy term is equal to product_cat” to ensure that your new field group only appears on the product_cat term edit screen
  6. Add the following code to the bottom of your functions.php file within your theme (or somewhere more appropriate if you use a theme framework or some kind)

function my_custom_product_order($q)
// fetch current category id from active query
$category_id = $q->get_queried_object_id();

// get array of all product IDs in current category
$product_ids = get_category_product_ids($category_id);

// get preferred order from ACF field
$product_ids_order_preferred = get_field('product_order', 'product_cat_' . $category_id);

// if we have some product sort order set…
// merge our preferred category ids array with the array of all products ids, and remove duplicates
$product_ids = array_unique(array_merge($product_ids_order_preferred, $product_ids));

// set the 'posts__in' argument to the new array of post IDs (unfortunately wordpress doesn’t let you just pass an array of IDs straight in here)
$q->set('post__in', $product_ids);

// set the query orderby value to observe the posts__in field
$q->set('orderby', 'post__in');

remove_action('woocommerce_product_query', 'custom_pre_get_posts_query');

add_action('woocommerce_product_query', ‘my_custom_product_order’);

and the following helper function to allow us to more easily fetch an array of all product IDs from within a specific category, which may come in handy for other things (stay DRY!)

// helper function to fetch all product IDs from a specific category ID

function get_category_product_ids($category_id)
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => -1,
'tax_query' => array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $category_id,
'operator' => 'IN'

$ids = get_posts($args);

return $ids;

Hopefully this will be of some use to people looking to have more granular control over their product sort order on a per category basis. Let us know in the comments if you think we missed anything, or if we can improve it.

One of Our Favourite Restaurants Gets a Makeover


We’ve been very excited to be working on a full rebrand for one of our favourite local restaurants, Maray, located on Bold Street.

The parisian inspired restaurant is famous for its delicious small plates and exciting cocktails, and they came to igoo for a new look that reflected their artistic presentation and continued growth.

igoo’s Jack and Amee have created a brand new logo, a full range of printed menus and exterior artwork for the restaurant, with a new website coming soon.

Home Sweet Home!


We’ve been in our new offices for a month now and we’re absolutely loving our new home!

There are some very exciting plans in the pipeline to develop our studio and we’re enjoying welcoming our clients into the new space.

Just a quick reminder that our new address is: Studio F, 16 Jordan Street, Liverpool, L1 0BP and our phone number is: 0151 291 7799.

Don’t forget, it’s best to contact us on: [email protected] if you need to get in touch – your dedicated project manager will get back to you as soon as possible.

We look forward to showing you around in the near future!

Updated Online Shop for George Roberts Scaffolding


It’s been a fantastic year for George Roberts Scaffolding, as they’ve recently expanded their facility and continue to win industry awards. To coincide with their recent expansion, we have made a few exciting changes to their existing website.

Their online shop has been redesigned and updated to accommodate their increased number of products, and to continue to make purchasing online, simple and quick.

This month, we’ve also introduced their new ‘Belt Builder’ function – which gives customers the option to fully customise their scaffolding belt with their personal choice of tools and accessories.

New Website for Stigma Rotary Coming Soon


This month, we’re developing a brand new responsive website for one of the world’s biggest and best tattoo machine brands, Stigma Rotary.

With a dedicated following from top tattoo artists, Stigma Rotary required a new website that would showcase their growing range of high quality tattoo machines, cartridges and parts, whilst working seamlessly on all devices.

The new site will allow customers to select official distributors by country, to view video demos of their tattoo machines and find detailed artist galleries.

Are You Reaching Your Customers Effectively?


Facebook has more than 900 million visits every day, which means that there are millions of potential customers who you could be targeting and driving back to your website.

As part of our range of marketing services available here at igoo, we offer Facebook advertising, as well as our daily social media management packages.

With Facebook adverts, you choose the people you want to reach, be it by location, age or interests. Your adverts are then placed within the stream of information people already view on Facebook – this means they’re more likely to see your adverts and take action.

Facebook adverts are highly targeted and actionable – you can reach people when they’re engaged and it’s great for targeting your previous customers, or those who have visited your website and not taken the action you wish they had.

Interested? It’s simple – just decide on a monthly spend and we’ll make sure we get the most out of your budget and reach the people you want to connect with.

If you want to explore online advertising with us here at igoo, get in touch with Camilla who can explain how Facebook Advertising could work for you.

We’re Moving!


We’re very excited to announce that the igoo offices are relocating to the Baltic Triangle, the rapidly growing creative and digital hub in Liverpool city centre!

Our new address will be: Studio F, 16 Jordan Street, Liverpool, L1 0BP and our phone number will remain the same: 0151 291 7799. 

We’ll be starting the big move on the afternoon of Friday 1st July so please bear with us if you have an enquiry and we’ll try to help as soon as possible.

As always, it’s best to contact us on: [email protected] and your dedicated project manager will be able to assist.

We’ll see you from Monday 4th July at our new address!

Hassle Free A-to-B with Cabfind


We’re delighted to have just launched the brand new responsive website for Cabfind, the UK’s most extensive private hire and executive car supplier.

The new website, which allows customers to book a taxi from anywhere in the UK, features links to off-site log in areas for easy client account management.

We’ve also created a flexible content builder, allowing Cabfind to arrange how their information is laid out. With custom icons and a comprehensive news section, the website is user friendly and easy to use.

If you would like to hear more about how we could transform your website, please get in touch with us today.

Liverpool Gift Company Launches


We have also just launched a redesigned, fully responsive website for The Liverpool Gift Company, a local online boutique selling lovely Liverpool inspired prints, cards, homeware and gifts.

The new website coincides with the launch of their international shipping, giving customers from all over the globe the opportunity to own a little piece of Liverpool!

To discover how we could give your online store a makeover, get in touch with us!

Exciting igoo News Coming Soon…


When one door closes, another one opens…

You can find us on Twitter & Facebook