Skip to content

Instantly share code, notes, and snippets.

@chrdesigner chrdesigner/function.php
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.