Skip to content

Instantly share code, notes, and snippets.

@gvgvgvijayan
Created March 15, 2020 12:04
Show Gist options
  • Save gvgvgvijayan/14df2a9c6332a8bf541bccb815713286 to your computer and use it in GitHub Desktop.
Save gvgvgvijayan/14df2a9c6332a8bf541bccb815713286 to your computer and use it in GitHub Desktop.
Partial, code snippet for the tutorial: http://www.vijayan.in/woocommerce-custom-product-sorting
<?php
/**
* Callback method to implement A-Z & Z-A sort functionality
*
* @since 1.0
*/
public function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ?
wc_clean( $_GET['orderby'] ) :
apply_filters( 'woocommerce_default_catalog_orderby',
get_option( 'woocommerce_default_catalog_orderby' ));
if ( 'reverse_list' == $orderby_value ) {
$args['orderby'] = 'title';
$args['order'] = 'desc';
} else if ('alpha_list' == $orderby_value) {
$args['orderby'] = 'title';
$args['order'] = 'asc';
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment