Skip to content

Instantly share code, notes, and snippets.

@chrdesigner
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrdesigner/ad52f4254520ea1c4c15 to your computer and use it in GitHub Desktop.
Save chrdesigner/ad52f4254520ea1c4c15 to your computer and use it in GitHub Desktop.
Custom sorting options - alphabet order - WooCommerce
<?php
// Custom sorting options
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 ('title_asc' == $orderby_value) {
$args['orderby'] = 'title';
$args['order'] = 'ASC';
$args['meta_key'] = '';
}elseif ('title_desc' == $orderby_value) {
$args['orderby'] = 'title';
$args['order'] = 'DESC';
$args['meta_key'] = '';
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment