• Hi,

    I just noticed that when using the WooCommerce Recently Viewed Products Widget it shows not in right logical order. I mean that the first product must be the recently viewed and should appear in the first but now it appears in the end.

    I tried to edit the file class-wc-widget-recently-viewed.php the below line

    $query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'rand' );

    But seems no action.

    Please help to figure out!

    Thanks!

    https://www.ads-software.com/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    The product ID’s are stored in a cookie: https://cld.wthms.co/d2kD/3o1Mfslj, and then queried with the post__in query arg.

    Here are the options for orderby: https://codex.www.ads-software.com/Class_Reference/WP_Query#Order_.26_Orderby_Parameters. So you should be able to use 'orderby' => 'post__in'. You may also need to reverse the order of the array:

    $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    This seems like it should be the default functionality – pending there isn’t a reason random sort was being used. As far as I can tell, that’s just always how it’s been since the widget was created.

    Opened a PR here: https://github.com/woothemes/woocommerce/pull/11768

    Thread Starter anahitipoint

    (@anahitipoint)

    Hi,

    Thank you for the answer.

    I tried to add your suggested code but nothing changed. The order remained the same. Am i editing right file?

    Am editing /woocommerce/includes/widgets/class-wc-widget-recently-viewed.php file.

    Any idea?

    Thanks!

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Try these changes: https://github.com/woothemes/woocommerce/pull/11768/commits/306e1dfa3930f3f8fd4b56698d83c2af50f153bf

    It seems to be working for me. You shouldn’t need to, but you could try deleting the woocommerce_recently_viewed cookie as well.

    Yes that is the correct file, but technically you shouldn’t ever edit core files as your changes will be lost on update. Normally, you’d need to create your own widget for the changes.

    Thread Starter anahitipoint

    (@anahitipoint)

    hey i did exactly as shown above but still no luck. I see wrong order. Still the recent one is the last one.

    I also deleted the existing cookie but no luck.

    Any ideas?

    Re the core files updates yes i know but what i could do, i need this part working like this.

    Thanks!

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Ehh, I’m not sure why it isn’t working for. Works for me on all my demo sites.

    If the product is already in the recently viewed cookie somewhere further down the list, it won’t be added again and it won’t be moved to the top. Maybe that is what you are experiencing?

    Here’s a video of it working: https://cld.wthms.co/17QhC/4NfAxITw

    Also, perhaps you’ve changed something else in core on accident? Replace the WooCommerce folder with a freshly downloaded copy and then make these changes.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change the order of products with WooCommerce Recently Viewed Widget’ is closed to new replies.