Ok, worked it out via a little workaround.
- Add a new sorting function in Woocommerce, something like: https://gist.githubusercontent.com/bekarice/0df2b2d54d6ac8076f84/raw/wc-sort-by-postmeta.php works nicely, but remove the bit about meta values and keys since we’re not sorting by custom fields (though that could be a good workaround too).
- Change the orderby to be ‘name’. Eg post slug rather than post title.
- Change all the products to remove the offending words from the slugs/permalinks so that /a-childs-story becomes /childs-story
- Choose the new sorting option as the default option in Woocommerce settings (products).
Here’s the final code for your functions.php:
/**
* Cool orderby function from Monkey Puzzle. Adapted from:
* Tutorial: http://www.skyverge.com/blog/sort-woocommerce-products-custom-fields/
**/
function monkey_ordering_args( $sort_args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch( $orderby_value ) {
// Name your sortby key whatever you'd like; must correspond to the $sortby in the next function
case 'slug':
$sort_args['orderby'] = 'name';
// Sort by ASC because we're using alphabetic sorting
$sort_args['order'] = 'asc';
break;
}
return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'monkey_ordering_args' );
// Add these new sorting arguments to the sortby options on the frontend
function monkey_add_new_orderby( $sortby ) {
// Adjust the text as desired
$sortby['slug'] = __( 'Sort by name', 'woocommerce' );
return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'monkey_add_new_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'monkey_add_new_orderby' );