Created
December 21, 2017 11:29
-
-
Save damiencarbery/d3683b047328cb442cd3457df1b0b2b7 to your computer and use it in GitHub Desktop.
WooCommerce - Allow sorting category archives by title, ascending and descending.
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 | |
/* | |
Plugin Name: Sort WooCommerce archives by title | |
Plugin URI: https://www.facebook.com/groups/advanced.woocommerce/permalink/1931386533542423/ | |
Description: Request on Facebook Advanced WooCommerce group - how to sort by title. | |
Author: Damien Carbery | |
Version: 0.1 | |
*/ | |
add_filter( 'woocommerce_default_catalog_orderby_options', 'swat_sort_by_title' ); // Add options to WooCommerce/Settings/Products/Display | |
add_filter( 'woocommerce_catalog_orderby', 'swat_sort_by_title' ); // Add options to sort dropdown on category page. | |
function swat_sort_by_title( $orderby_array ) { | |
$orderby_array[ 'title' ] = 'Sort by title (A-Z)'; | |
$orderby_array[ 'title-desc' ] = 'Sort by title (Z-A)'; | |
return $orderby_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment