My initial goal is to be able to display Woocommerce Products in the sidebar, sorted by Title. Currently the only sorting options in this widget are Date, Price, Random and Sales.
I was able to add the Title sorting option in 2 parts in class-wc-widget-products.php:
'orderby' => array(
'type' => 'select',
'std' => 'date',
'label' => __( 'Order by', 'woocommerce' ),
'options' => array(
'title' => __( 'Title', 'woocommerce' ),
'date' => __( 'Date', 'woocommerce' ),
'price' => __( 'Price', 'woocommerce' ),
'rand' => __( 'Random', 'woocommerce' ),
'sales' => __( 'Sales', 'woocommerce' ),
),
And here:
switch ( $orderby ) {
case 'title' :
$query_args['orderby'] = 'title';
break;
case 'price' :
$query_args['meta_key'] = '_price';
$query_args['orderby'] = 'meta_value_num';
break;
case 'rand' :
$query_args['orderby'] = 'rand';
break;
case 'sales' :
$query_args['meta_key'] = 'total_sales';
$query_args['orderby'] = 'meta_value_num';
break;
default :
$query_args['orderby'] = 'date';
}
This customization works fine, but:
My question: where should I save this customized "class-wc-widget-products.php
" file preventing it from being overwritten at the next Woocommerce update?
OR... is there a more elegant way to accomplish this? Thank You!