We have updated one of our customers Wp-Ecommerce plugin. We found that the products categories where sortable using drag and drop. The fact is that feature does not save the order you set using it.

The fix is really simple, but it is so difficult to have a single line of code (even if its a fix) included in Wp-Ecommerce that we publish it here. Fortunately, the fix doesn’t need to be applied to core files.

This hack simply replaces the wpsc_ajax_set_category_order() function with our own. Ideally, it would be better to modify the core javascript that orders the categories. Nervermind it works and will hopefully survive to Wp-Ecommerce updates.

To fix that issue, simply paste that code in your active theme’s functions.php file:

add_action('admin_init', 'my_admin_init'); 

function my_admin_init () {
	remove_action( 'wp_ajax_category_sort_order', 'wpsc_ajax_set_category_order' );
	add_action( 'wp_ajax_category_sort_order', 'my_wpsc_ajax_set_category_order' );

function my_wpsc_ajax_set_category_order(){

  global $wpdb;
  $sort_order = $_POST['sort_order'];
  $parent_id  = $_POST['parent_id'];
  $result = true;
  foreach( $sort_order as $key=>$value ){
        // ignore empty value (bad javascript makes them)
  	if(!$value) continue;
  	$value = substr($value, strpos($value, '-')+1); // removes the "tag-" prefix from object id

    if( ! wpsc_update_meta( $value, 'sort_order', $key, 'wpsc_category' ) )
      $result = false;

18 Comments to Fixing categories ordering in Wp Ecommerce 3.8.4. Leave one.

  1. Extremely useful bit of code, thanks!

  2. Lee Willis says:


    If there’s a fix that needs making in core – you can submit an issue explaining the problem, and the associated fix here:


    I’m not clear on what the issue is in order to test the validity of this fix, but if you can provide more detail on a ticket that’d be great!

  3. Laurent says:


    We tried in the past, not only submitting tickets for bugs, but also providing the patches to fix those bugs. Even the simplest patch never went to core. So we gave up.

    Then we realized that this plug-in really has a messy code to us, it also uses its own templating api instead of using the wordpess one.

    We have just discovered Jigoshop, a young project, well written. The devs are very opened to contributions and there sources are on GitHub, which makes contributing a breeze because of the GitHub’s oneclick fork/push/pull feature.

  4. Mary says:

    Thank YOU !!! this is just what I needed to re-order categories easily

  5. Fernand Fenech says:

    excellent! worked like a charm! :)

  6. Thanks so much – this is such an easy & straightforward solution to a problem that’s taken up a whole day of my time!

  7. Violet says:

    Would this work with the 3.78 release?

    I desperately need to figure out a way to re-order the categories as they appear on the main “products page”

    I had thought hard-coding the html into a wordpress page template might work but can’t set different templates for the category and single products pages.

  8. Laurent says:

    It may not.

    We dropped any usage of WP E commerce as, for us, it is a badly written plug-in. Our advice is to switch to Jigoshop as we jumped into the development of that great E-commerce plug-in. It has categories ordering support as we did implement it.


  9. we says:

    i want to add discount on categories in wp ecomm plug in in cart class……

  10. I have just used the code since the category sorting was all messed up. And it seems to work still in the WPEC 3.8.

  11. GRAPHICpilot says:

    +1 on your fix for WP eCommerce Version! Thank you so much for this fix! I’ve been working tirelessly on a website with a shopping cart for a winery in the Redding, CA area this brought my stress level down. Works perfectly. I thought the web design client was going to be disappointed if I had to tell them I couldn’t reorder their products in the way they wanted!

  12. Brian says:

    This worked for version too!

    Paste it into the start of your functions.php (just after the <php? open tag and then drag/drop your categories as normal. Then go to the sidebar widget and the categories should be in the order you chose. hen click save on the widget and it's fixed!

    Thank you so much for this code bro!

  13. Anand says:

    Thank you very much
    Its awesome coading

  14. Tejas says:

    i am new to word press and wp e-commerce.

    i want to re-order the categories.
    and i found this block of code.
    I just added the above code as per the instructions and tested but have no result.

    Can anybody guide me how to use this code?
    or is it required to add a field in the table?

    help please…


  15. Tomek says:

    It didn’t work for me. :( I tried everything. Have you got any solve for version 3.7.1?

  16. Corinne says:

    Does anyone know if this fix works on the latest version of WP-ecommerce, I’m still having trouble with the categories displaying properly. I want to display them in alphabetical order but that is not working. I keep trying to drag-n-drop the categories on the Products->Categories page but it is not fully working. I’m sorting them via drag-n-drop but then they are not appearing that way when viewing the website. (I think it could be related to the fact that I have 2 pages of categories and there doesn’t seem to be a way to drag-n-drop across pages.) In any case, I’m very frustrated with this. If anyone can help I’d really appreciate it. The website I’m working on is http://clearpointweb.com/symanskimh. THanks!

  17. Nice one, worked perfectly. Thanks

  18. Cvanger says:

    Thank you very much! it was very useful. :D:D

Leave a Reply to Corinne Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>