Woocommerce custom search filter
-
i use woocommerce plugin.
i want to add new sort filter by short description(post_excerpt) in product list page.
so i coeded as below in my theme.(functions.php)===========================================
add_filter(‘woocommerce_get_catalog_ordering_args’, ‘custom_woocommerce_get_catalog_ordering_args’);function custom_woocommerce_get_catalog_ordering_args( $args ) {
if (isset($_SESSION[‘orderby’])) {
switch ($_SESSION[‘orderby’]) :
case ‘date_asc’ :
$args[‘orderby’] = ‘date’;
$args[‘order’] = ‘asc’;
$args[‘meta_key’] = ”;
break;
case ‘price_desc’ :
$args[‘orderby’] = ‘meta_value_num’;
$args[‘order’] = ‘desc’;
$args[‘meta_key’] = ‘_price’;
break;
case ‘title_desc’ :
$args[‘orderby’] = ‘title’;
$args[‘order’] = ‘desc’;
$args[‘meta_key’] = ”;
break;
case ‘excerpt_desc’ :
$args[‘orderby’] = ‘excerpt’;
$args[‘order’] = ‘desc’;
$args[‘meta_key’] = ”;
break;
endswitch;
}
return $args;
}add_filter(‘woocommerce_catalog_orderby’, ‘custom_woocommerce_catalog_orderby’);
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby[‘title_desc’] = ‘Reverse-Alphabetically’;
$sortby[‘price_desc’] = ‘Price (highest to lowest)’;
$sortby[‘date_asc’] = ‘Oldest to newest’;
$sortby[‘excerpt_desc’] = ‘Sort by Excerpt’;
return $sortby;
}
======================================but my code isn`t well work.
the sort by excerpt isn`t well work.pls help me.
Thank you.
Best regards.
- The topic ‘Woocommerce custom search filter’ is closed to new replies.