Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    For that,

    you need to add below code in functions.php

    function alphabetical_shop_ordering( $sort_args ) {
    $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    if ( 'ascending' == $orderby_value ) {
    $sort_args['orderby'] = 'title';
    $sort_args['order'] = 'asc';
    $sort_args['meta_key'] = '';
    }
    if ( 'descending' == $orderby_value ) {
    $sort_args['orderby'] = 'title';
    $sort_args['order'] = 'desc';
    $sort_args['meta_key'] = '';
    }
    return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'alphabetical_shop_ordering' );
    
    function custom_wc_catalog_orderby( $sortby ) {
    	$sortby['ascending'] = 'Sort by (A-Z)';
    	$sortby['descending'] = 'Sort by (Z-A)';
    	return $sortby;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_wc_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_wc_catalog_orderby' );

    tested and Worked

    Thank you

    Thread Starter slimmz

    (@slimmz)

    Thanks for reaching out @aimsinfosofts

    Yes that is working, is there also a way to set the ASCENDING option to be the default?

    And also make the search result to only querry the product tittle (must contain the first word)?

    Hello,

    Please follow below steps in the backend:
    Step 1: Appearance -> Customize
    Step 2: Click on Woocommerce
    Step 3: click on Product Catalog and choose option to Default product sorting.
    Please check below screenshot.
    https://prnt.sc/1y1hwzw

    For that you need to more customization and you have required knowledge of php and woocommerce.
    Also if you update the default search query via hook, It will be update sitewide as per my knowledge in WooCommerce.

    Thank you

    Thread Starter slimmz

    (@slimmz)

    All right @aimsinfosofts

    Thanks for your support!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Product Search Sorting Option’ is closed to new replies.