Caleb Burks on "Change the order of products with WooCommerce Recently Viewed Widget"

ساخت وبلاگ

anahitipoint
Member
Posted 1 day ago #

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://wordpress.org/plugins/woocommerce/

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

Here are the options for orderby: https://codex.wordpress.org/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 ) ) );

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

anahitipoint
Member
Posted 54 minutes ago #

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!

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.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 432 تاريخ : پنجشنبه 4 شهريور 1395 ساعت: 14:08