Created
May 22, 2015 07:01
-
-
Save zlove/51c3db742aef49218083 to your computer and use it in GitHub Desktop.
Order WooCommerce products by Title, ignoring a leading "The"
This file contains hidden or 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
add_filter('posts_orderby', 'zbyte_edit_posts_orderby'); | |
function zbyte_edit_posts_orderby($orderby_statement) { | |
global $wp_query; | |
$is_product_list = | |
is_shop() || | |
is_product_category() || | |
is_product_tag(); | |
if ( $is_product_list && $wp_query->get('orderby') == 'title' ) { | |
$orderby_statement = "REPLACE(LOWER(wp_posts.post_title), 'the ', '') ASC"; | |
} | |
return $orderby_statement; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checking for the 'orderby' of 'title' should prevent this from running if the WooCommerce store admin has selected a different product ordering method from the default "Custom Ordering + name". A custom ordering will still override this. Remove the 'orderby' == 'title' check to make this override the sort on all product list pages.