Woocommerce: Show Products in Alphabetic order

后端 未结 5 602
轮回少年
轮回少年 2021-02-06 19:40

Ok I know it\'s might be a silly question or you may think it was asked dozen times. but either I am desperate and missed something or this is some unique problem. Anyway, I nee

5条回答
  •  攒了一身酷
    2021-02-06 20:23

    To expand on @helgatheviking's answer, I tried that and it sorted in (descending) alphabetical order but only if the Alphabetical option was chosen on the drop-down because of the if ( 'alphabetical' == $orderby_value ) condition.

    This is mod which sorts in ascending alphabetical order by default, the differences being the condition if ('alphabetical' == $orderby_value || 'menu_order' == $orderby_value) and $args['order'] = 'ASC'

    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    
    function custom_woocommerce_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 ( 'alphabetical' == $orderby_value || 'menu_order' == $orderby_value ) {
            $args['orderby'] = 'title';
            $args['order'] = 'ASC';
        }
    
        return $args;
    }
    
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    
    function custom_woocommerce_catalog_orderby( $sortby ) {
        $sortby['alphabetical'] = __( 'Alphabetical' );
        return $sortby;
    }
    

    The site I was working on has grouped products so I made sure they were alphabetical as well...

    add_filter( 'woocommerce_grouped_children_args', 'custom_grouped_children_args' );
    function custom_grouped_children_args( $args ){
        $args['orderby'] = 'title';
        $args['order'] = 'ASC';
        return $args;
    }
    

提交回复
热议问题