WordPress.org

Ready to get started?Download WordPress

Forums

Woocommerce custom search filter (4 posts)

  1. developking
    Member
    Posted 1 year ago #

    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.

  2. hegero
    Member
    Posted 1 year ago #

    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?

  3. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

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

    http://wordpress.org/support/plugin/woocommerce

  4. hegero
    Member
    Posted 1 year ago #

    Thanks! I'll try that.

Topic Closed

This topic has been closed to new replies.

About this Topic