• 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m also very interested in any suggestions on this. I have a similar problem, only I’m trying to sort by _product_attributes. It seems like the orderby meta_value_num is not producing any result at all. I’ve tried a number of different settings, even the one provided by WooDocs ($args[‘orderby’] = ‘meta_value_num’; $args[‘order’] = ‘desc’; $args[‘meta_key’] = ‘_price’;), and nothing! Getting me kind of frustrated.

    Anyone have a clue on what’s going on?

    Starting your own thread on the WooCommerce sub-forum might be more fruitful:

    https://www.ads-software.com/support/plugin/woocommerce

    Thanks! I’ll try that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce custom search filter’ is closed to new replies.