Quote from boehmvk on May 25, 2020, 19:50
Hey again Pablo,
I'm experiencing a strange behaviour: When you first visit the shop, all the items are sorted by date old to new. When you go to page 2 or 3, the plugin starts to shuffle and randomising the results. So, they're no longer in any order / truly random which is what I want to have all the time. However: It is showing some of the results from the first page again as well.
I tried to achieve a full randomisation through the php code below. However, the problem still persists that as soons as you go to the next page of filter results (e.g. page 2 of 3), products of page 1 or any other page are shown as well. So it indeed does randomise the results, but it does not exclude those products it had already shown on the other pages. The same happens, when you then move back to page 1 again. It randomises the results and shows half of the products from page 2.
Any ideas on how we can fix this?
Thank you in advance!
That's my php:
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'random_list' == $orderby_value ) {
$args['orderby'] = 'rand';
$args['order'] = '';
$args['meta_key'] = '';
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['random_list'] = 'Random';
return $sortby;
Hey again Pablo,
I'm experiencing a strange behaviour: When you first visit the shop, all the items are sorted by date old to new. When you go to page 2 or 3, the plugin starts to shuffle and randomising the results. So, they're no longer in any order / truly random which is what I want to have all the time. However: It is showing some of the results from the first page again as well.
I tried to achieve a full randomisation through the php code below. However, the problem still persists that as soons as you go to the next page of filter results (e.g. page 2 of 3), products of page 1 or any other page are shown as well. So it indeed does randomise the results, but it does not exclude those products it had already shown on the other pages. The same happens, when you then move back to page 1 again. It randomises the results and shows half of the products from page 2.
Any ideas on how we can fix this?
Thank you in advance!
That's my php:
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'random_list' == $orderby_value ) {
$args['orderby'] = 'rand';
$args['order'] = '';
$args['meta_key'] = '';
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['random_list'] = 'Random';
return $sortby;