Product sorting not working properly alphabetically

This topic has 6 replies, 2 voices, and was last updated 2 weeks, 1 day ago ago by Andrew Mitchell

  • Avatar: John
    John
    Participant
    September 23, 2026 at 10:39

    Hello!
    I am using the XStore theme and I am experiencing a sorting issue in category-products.

    Even when I try to sort products alphabetically (A-Z), WooCommerce/XStore does not sort them properly, and products are completely out of order, if you check the last products, they should be next to “Κολώνα” products.
    Check screenshot*
    Check link: https://shopfitting.gr/product-category/%ce%ba%ce%bf%ce%bb%cf%8e%ce%bd%ce%b5%cf%82-%ce%b4%ce%b9%ce%ac%cf%84%cf%81%ce%b7%cf%84%ce%b5%cf%82/

    Specifically, I’d like in my ‘Kolones Diatrites’ category (ID 43), I need products starting with the word ‘Κολώνες’ to appear first, but standard alphabetical sorting or custom snippets are either breaking the page layout or failing to sort correctly.

    Can you please provide a solution or a working snippet compatible with XStore to fix the alphabetical sorting and the option to prioritize products with “Κ” letter in this category?”

    Also, the filter with the number of products to show (12, 24, 36, All), it works only the “All” option. The other options still loading if you select them.

    Thank you

    Please, contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    5 Answers
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 24, 2026 at 09:28

    Hello, John,

    Could you please provide temporary wp-admin and FTP access? We will check what can be done to help you.

    For FTP access, we require the following details: FTP host, FTP username, FTP password, FTP port, and FTP encryption type. If you need assistance in creating these credentials, please reach out to your hosting provider who will guide you through the process.

    Best Regards,
    8Theme’s Team

    Avatar: John
    John
    Participant
    September 24, 2026 at 10:37

    I’ve sent you wp admin and credentials. I’ve added also wp file manager so you don’t need ftp credentials. You can make any change from there.

    Thanks

    Please contact administrator
    for this information.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 24, 2026 at 14:46

    We checked the “Κολώνες Διάτρητες” category. WooCommerce’s default sorting is not purely alphabetical it combines the custom product order with the product title. This is why some Κολώνα… products appear separately at the end.

    To display products beginning with Κ first and then sort the remaining products alphabetically, please remove any previous sorting snippets and add the following code to the functions.php file of your child theme:

    function shopfitting_is_kolones_category() {
    	return function_exists( 'is_product_category' )
    		&& is_product_category()
    		&& 43 === (int) get_queried_object_id();
    }
    
    add_filter( 'woocommerce_default_catalog_orderby', function ( $orderby ) {
    	return shopfitting_is_kolones_category()
    		? 'shopfitting_k_first'
    		: $orderby;
    }, 20 );
    
    add_filter( 'woocommerce_catalog_orderby', function ( $options ) {
    	if ( ! shopfitting_is_kolones_category() ) {
    		return $options;
    	}
    
    	return array(
    		'shopfitting_k_first' => 'Κολώνες πρώτα, μετά Α–Ω',
    		'title'               => 'Όνομα: Α–Ω',
    	) + $options;
    }, 20 );
    
    add_filter(
    	'woocommerce_get_catalog_ordering_args',
    	function ( $args, $orderby, $order ) {
    		if (
    			shopfitting_is_kolones_category()
    			&& 'shopfitting_k_first' === $orderby
    		) {
    			$args['orderby']  = 'title';
    			$args['order']    = 'ASC';
    			$args['meta_key'] = '';
    		}
    
    		return $args;
    	},
    	20,
    	3
    );
    
    add_filter(
    	'posts_orderby',
    	function ( $orderby_sql, $query ) {
    		if ( is_admin() && ! wp_doing_ajax() ) {
    			return $orderby_sql;
    		}
    
    		if (
    			! $query->is_main_query()
    			|| ! $query->is_tax( 'product_cat', 43 )
    		) {
    			return $orderby_sql;
    		}
    
    		$selected_orderby = isset( $_GET['orderby'] )
    			? wc_clean( wp_unslash( $_GET['orderby'] ) )
    			: 'shopfitting_k_first';
    
    		if ( is_array( $selected_orderby ) ) {
    			$selected_orderby = reset( $selected_orderby );
    		}
    
    		if ( 'shopfitting_k_first' !== $selected_orderby ) {
    			return $orderby_sql;
    		}
    
    		global $wpdb;
    
    		$uppercase_k = $wpdb->esc_like( 'Κ' ) . '%';
    		$lowercase_k = $wpdb->esc_like( 'κ' ) . '%';
    
    		return $wpdb->prepare(
    			"
    			CASE
    				WHEN {$wpdb->posts}.post_title LIKE %s
    					OR {$wpdb->posts}.post_title LIKE %s
    				THEN 0
    				ELSE 1
    			END ASC,
    			{$wpdb->posts}.post_title ASC,
    			{$wpdb->posts}.ID ASC
    			",
    			$uppercase_k,
    			$lowercase_k
    		);
    	},
    	999,
    	2
    );
    

    This customization applies only to product category ID 43. Other sorting options, such as price, popularity, and latest products, will continue to work normally.

    Regarding the products-per-page selector: it currently contains 16 / 24 / 36 / All. We tested the 24 and 36 options, and both loaded successfully. Since this category currently contains only 16 displayed products, selecting a higher number does not visually change the product grid.

    If the loading problem still occurs on your side, please clear all website/browser caches and send us a short screen recording showing the issue in an incognito window.

    Best Regards,
    8Theme’s Team

    Avatar: John
    John
    Participant
    September 24, 2026 at 17:22

    Thank you very much for the solution.

    If I need to make some categories to have as default sorting alphabetical, how can achieve it? Because there’s no sense if it is like that way of mixed products.

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 25, 2026 at 12:45

    Hello, John,

    You’re welcome.

    Yes, you can set pure alphabetical sorting as the default for selected product categories. Add the following code below the previous snippet in the child theme’s functions.php file:

    /**
     * Category IDs that should use alphabetical sorting by default.
     */
    function shopfitting_alphabetical_category_ids() {
    	return array(
    		123,
    		456,
    	);
    }
    
    /**
     * Check whether the current product category should be alphabetical.
     */
    function shopfitting_is_alphabetical_category() {
    	return function_exists( 'is_product_category' )
    		&& is_product_category( shopfitting_alphabetical_category_ids() );
    }
    
    /**
     * Use product title A–Z as the default sorting.
     */
    add_filter( 'woocommerce_default_catalog_orderby', function ( $orderby ) {
    	if ( shopfitting_is_alphabetical_category() ) {
    		return 'title';
    	}
    
    	return $orderby;
    }, 30 );
    
    /**
     * Add the alphabetical option to the sorting dropdown.
     */
    add_filter( 'woocommerce_catalog_orderby', function ( $options ) {
    	if ( shopfitting_is_alphabetical_category() ) {
    		$options['title'] = 'Sort by name: A to Z';
    	}
    
    	return $options;
    }, 30 );

    Replace 123 and 456 with the IDs of the categories that should use alphabetical sorting. You can add as many IDs as needed

    This will sort products in those categories strictly by their titles, from A to Z, instead of using WooCommerce’s mixed menu_order+ title sorting.

    If category ID 43 should keep the special “Κ products first” sorting from the previous code, do not add 43 to this list. If you want category 43 to use normal alphabetical sorting instead, remove the previous special sorting snippet and add 43 here.

    Best Regards,
    8Theme’s Team

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.