Created
March 15, 2020 12:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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