So, I did some digging but wasn't able to find the correct way to do this.
I have some products on WooCommerce (Wordpress), but their title is composed of Letters mixed with numbers. I need those products to be print like this (e.g.):
FNC21000-C
FNC24500-C
FNC232500-C
But, of course, Wordpress gives me:
FNC21000-C
FNC232500-C
FNC24500-C
Is there anyway to achieve this?
I think there's something I might do on WP_Query but I'm really a newbie with PHP, and I know some of the possible fixes are on PHP, some others on MySQL... and the fact that the title is BOTH string and integer, makes me feel clueless on how to write this...
Does anyone has some suggestions?
Below, class-wc-query.php, which I BELIEVE to be the file I need to edit:
/**
* Returns an array of arguments for ordering products based on the selected values.
*
* @access public
* @return array
*/
public function get_catalog_ordering_args( $orderby = '', $order = '' ) {
// Get ordering from query string unless defined
if ( ! $orderby ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
// Get order + orderby args from string
$orderby_value = explode( '-', $orderby_value );
$orderby = esc_attr( $orderby_value[0] );
$order = ! empty( $orderby_value[1] ) ? $orderby_value[1] : $order;
}
$orderby = strtolower( $orderby );
$order = strtoupper( $order );
$args = array();
// default - menu_order
$args['orderby'] = "strlen('title') => 'ASC', 'title' => 'ASC'";
// $args['orderby'] = 'title';
$args['order'] = $order == 'DESC' ? 'DESC' : 'ASC';
$args['meta_key'] = '';
switch ( $orderby ) {
case 'rand' :
$args['orderby'] = 'rand';
break;
case 'date' :
$args['orderby'] = 'date ID';
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC';
break;
case 'price' :
$args['orderby'] = "meta_value_num ID";
$args['order'] = $order == 'DESC' ? 'DESC' : 'ASC';
$args['meta_key'] = '_price';
break;
case 'popularity' :
$args['meta_key'] = 'total_sales';
// Sorting handled later though a hook
add_filter( 'posts_clauses', array( $this, 'order_by_popularity_post_clauses' ) );
break;
case 'rating' :
// Sorting handled later though a hook
add_filter( 'posts_clauses', array( $this, 'order_by_rating_post_clauses' ) );
break;
case 'title' :
$args['orderby'] = "strlen('title') => 'ASC', 'title' => 'ASC'";
//$args['orderby'] = 'meta_value meta_value_num title';
$args['order'] = $order == 'DESC' ? 'DESC' : 'ASC';
break;
}
return apply_filters( 'woocommerce_get_catalog_ordering_args', $args );
}