Add New Catalog Ordering Argument On Shop Page

You can add a custom ordering option for the catalog page. Here we have the steps to add a custom ordering option in the catalog page.

WooCommerce has 5 standard sorting options:

Sorting can be used in arranging the catalog page products.

Add the below code to function.php or in the custom plugin file to add a new sorting option on the catalog page.

add_filter( "woocommerce_catalog_orderby", "demo_woocommerce_catalog_orderby", 20 );
function demo_woocommerce_catalog_orderby( $orderby ) {
  $orderby["a_to_z"] = __('A to Z', 'woocommerce');
  $orderby["z_to_a"] = __('Z to A', 'woocommerce');
return $orderby;
}

//new sort arg
add_filter( 'woocommerce_get_catalog_ordering_args', 'demo_woocommerce_get_catalog_ordering_args', 20 );
function demo_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 ( 'a_to_z' == $orderby_value ) {
    $args['orderby'] = 'name';
    $args['order'] = 'ASC';
  }
  if ( 'z_to_a' == $orderby_value ) {
    $args['orderby'] = 'name';
    $args['order'] = 'DESC';
  }
return $args;
}

Two new ordering arguments “Z to A” and “A to Z” is added to the dropdown.

Now select Z to A to sort the product in DESC alphabetical order.

Now select A to Z to sort the product in ASC alphabetical order.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories