This topic has 4 replies, 3 voices, and was last updated 2 years, 6 months ago ago by Olga Barlow
Hello, I would like to know how to manage the option the default sorting of products in the shop section and the product listing section and in categories to show sales products before all other. At the moment i think that the products are randomly sorted. I would like when a client open some category to see first of all the products which are on sale.
Thanks in advance.
Best regards!
Hello,
All the available settings for the products sorting you can find in Appearance > Customize > WooCommerce > Product Catalog > Default Product Sorting > choose Default sorting. After that change the order of the products according to your needs using the sorting option https://gyazo.com/447b64249daa28be2a2ecd019fba9d87
Regards
Thank you for the answer!
I had to add additional code to functions so woocommerce can show first the products on sale and after that to select the option from Appearance > Customize > WooCommerce > Product Catalog > Default Product Sorting > choose Sales. For other users that want to have this option this is the function:
add_filter( 'woocommerce_get_catalog_ordering_args', 'wcs_get_catalog_ordering_args' );
function wcs_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 ( 'on_sale' == $orderby_value ) {
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
$args['meta_key'] = '_sale_price';
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'wcs_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'wcs_catalog_orderby' );
function wcs_catalog_orderby( $sortby ) {
$sortby['on_sale'] = 'Sales';
return $sortby;
}
Hello,
Thank you very much that you shared your solution.
Regards
Tagged: default sorting, persuasive, product sorting, template, woocommerce, wordpress
The issue related to '‘Having problem with default sorting of the products’' has been successfully resolved, and the topic is now closed for further responses