Using Simple Sorts along with WooCommerce version 3.x

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Starting WooCommerce 3.0, Automattic developers introduced a drastically modified framework. This put the woocommerce on the right track since, like consolidating the MultiSite environment compatibility. But this come with a small drawback, many thing has changed making compatibility with other plugins a bit of an issue.

The Advanced Post Types Order plugin rely on WordPress Queries to identify what sort to use, depending on set-up. Before WooCommerce version 3.x, a query contained a single taxonomy term so it was pretty straightforward for the Advanced Post Types Order plugin to identify the right order list from a simple sort. Starting WooCommerce version 3.x, this become harder as a query would contain 2 taxonomies instead one, the default taxonomy and a new one called ‘product_visibility’ which before where saved as a custom field. Giving the new structure, an advanced sort set-up is naturally required to make a match. However that potentially become a problem over the time, since many WooCommerce categories (or other type of taxonomies) will require sorting. Starting Version 3.9.8.5, Advanced Post Types Order plugin received a code update to make such queries to match a simple sort, so there is no need to set-up individual sorts for every term, but instead use a simple sort and use the term switch selector to customize order for other terms. In other words, it works the same way as before releasing WooCommerce 3.0

As default, when a WooCommerce query, the Advanced Post Types Order will seek for ‘product_cat’ and ‘product_tag’taxonomies. If additional taxonomies are registered for WooCommerce product post type and are required to be used along the same simple sort, a simple filter can be used to pass through the data.
Presuming we need to set a new taxonomy called ‘product_type’, the following code can e used:

	add_filter('APTO/query_filter_valid_data/woocommerce_taxonomies', 'APTO_query_filter_valid_data_woocommerce_taxonomies', 10, 2 );
	function APTO_query_filter_valid_data_woocommerce_taxonomies( $search_for_taxonomies, $query )
        {
            /**
            * Add the custom taxonomy to the list
            * 
            * Format is:
            * taxonomy = number of terms it should expect to be found
            */
            $search_for_taxonomies['product_type']  =  1;            
            
            return $search_for_taxonomies;    
        }
 

The code should be placed within theme functins.php or a custom plugin.