If you’re using WooCommerce to sell products on your WordPress site, you may want to give your customers the ability to sort the product catalogue by custom fields. This can be especially useful if you have a large number of products and want to give your customers the ability to filter and sort the products by various criteria.

One way to do this is by using the Advanced Custom Fields (ACF) plugin. ACF is a popular WordPress plugin that allows you to create custom fields for your posts, pages, and custom post types. You can use ACF to create custom fields for your WooCommerce products and then use those fields to sort the product catalogue.

In this article, we’ll walk you through the steps for sorting the WooCommerce product catalogue by ACF fields. We’ll start by installing and setting up the ACF plugin, then we’ll create the custom fields for our products, and finally, we’ll add the code to sort the product catalogue by those fields.

  1. Install and set up the ACF plugin: The first step is to install and activate the ACF plugin on your WordPress site. Once the plugin is activated, you’ll need to create the custom fields for your products. To do this, go to Custom Fields > Add New in the WordPress dashboard.
  2. Create the custom fields: Next, you’ll need to create the custom fields that you want to use to sort the product catalogue. You can create any type of field that you like, such as text, select, or checkbox fields. Just make sure to give your fields appropriate names and descriptions.
  3. Add the code to sort the product catalogue: Once you’ve created your custom fields, you’ll need to add some code to your WordPress site to sort the product catalogue by those fields. Here is an example of how you might do this:
// Add a custom sorting option to the WooCommerce shop page add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_get_catalog_ordering_args( $args ) {   $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );   if ( 'custom_field' == $orderby_value ) {     $args['orderby'] = 'meta_value_num';     $args['order'] = 'asc';     $args['meta_key'] = 'custom_field';   }   
return $args; } 
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' ); 
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' ); 
function custom_woocommerce_catalog_orderby( $sortby ) { $sortby['custom_field'] = 'Custom Field'; return $sortby; }

This code adds a custom sorting option to the WooCommerce shop page called “Custom Field.” When a user selects this option, the product catalogue will be sorted by the value of the “custom_field” ACF field. The code also specifies that the products should be sorted in ascending order.

4. Test the sorting: Once you’ve added the code to your site, you can test the sorting to make sure it’s working correctly. Go to the WooCommerce shop page on your site and try selecting the “Custom Field” sorting option. You should see the product catalogue update to reflect the selected sorting option.

In conclusion, sorting the WooCommerce product catalogue by ACF fields is a simple and effective way to give your customers more control over how they view your products. By installing the ACF plugin, creating the custom fields, and adding the code to your WordPress site, you can easily enable this feature on your site.

Let's Get In Touch!


Ready to start your project? Get in touch to have a chat!