• Resolved kaynoba

    (@kaynoba)


    Hello all,

    I have a Woocommerce shop where the different attributes / variations are ordered alphabetically when you click the ‘select’ on a product page. I’m currently trying to figure out how I can sort them based on the ordening in the backend.

    Specifically: I have options 10gr 50gr 100gr 1000gr. it should list like that 10gr->50-gr->500gr->1000gr. But woocommerce automatically change sorting list as alphabetical and shows up 10gr->1000gr->50gr->500gr

    Any help would be more than welcome. I’ve been googling for an hour now and can’t seem to find the solution. I have thousand product like that variations have.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Kaynoba,

    In your theme’s functions.php file just write the following code :

    add_filter( 'woocommerce_get_product_terms', 'cedcommerce_variation_sort');
    
    function cedcommerce_variation_sort($terms)
    {
    	if($terms)
    	{
    	     usort($terms, "cedcommerce_sort");
    	}
    	return $terms;
    }
    
    function cedcommerce_sort($a, $b)
    {
         return $a->name-$b->name;
    }

    It will work. Enjoy !!!

    Thread Starter kaynoba

    (@kaynoba)

    Hello cedcommerce,

    It Works. Thank you for your great support.

    Have a nice day..

    Ali Enver Isman

    Jb

    (@adventureweb)

    Hello, looking for the exact same thing except need to sort by price (low to high). This will solve issue and display everything correctly in the drop menu (smll, med, large, XL, XXL) and it would be consistent with other options like colors.

    Is sorting by the variation prices possible using same/similar code as this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change alphabetical sorting of attributes / variations on product page in Woocom’ is closed to new replies.