• Resolved JayFry

    (@jayfry)


    Hello!

    As I know woocommerse is sorting up-sells in random order.
    And to sort it by price you need to add this code in your function.php

    
    function filter_woocommerce_upsells_orderby( $orderby ) { 
        return 'price'; 
    }; 
    add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );  
    

    It worked for me.
    But I couldn`t figure out how to reverse order of up-sells.
    This code sorting out products from high to low price, and I need the opposite.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’ll have a go if you can debug it:

    // remove the upsells action using the same priority as original add_action()
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
    // add my custom upsells function in the same place
    add_action( 'woocommerce_after_single_product_summary', 'custom_upsell_display', 15 );
    function custom_upsell_display() {
      // default parameters:
      // woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' )
      // call it with my parameters
      woocommerce_upsell_display( -1, 4, 'price', 'asc' );
    }
    
    Thread Starter JayFry

    (@jayfry)

    Thank you for answer, but your solution worked in older versions of woocommerce. Now it is not, I have just tested it.

    • This reply was modified 6 years, 11 months ago by JayFry.

    I got it to work in 2017 theme and in storefront with a slight mod. All latest. If you are using a wordpress.org theme I’ll try it with that? In what way did it not work?

    Thread Starter JayFry

    (@jayfry)

    It is depending on woocommerce version and since release of v3.x your code is not working any more. Up-sells keeps being placed in random order on every page reload.

    • This reply was modified 6 years, 11 months ago by JayFry.
    • This reply was modified 6 years, 11 months ago by JayFry.

    Working with WC 3.1.1 on 2017 theme.

    What theme are you using?

    Thread Starter JayFry

    (@jayfry)

    You was totally right. Your code is working. The problem was in my functions.php, it had some code that was contradicting with yours.
    Thank you a lot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Up-sells order’ is closed to new replies.