I am using below code for custom sorting in woocommerce. This is working fine. The only thing is that I have to sort according to numbers. I have used meta_type = UNSIGNED
but this is not working.
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'timer' == $orderby_value ) {
$args['meta_key'] = '_auction_dates_to_time';
$args['meta_type'] = 'UNSIGNED';
$args['orderby'] = "meta_value";
$args['order'] = 'ASC';
$args['paged'] = $paged;
}
if ( 'timer-desc' == $orderby_value ) {
$args['meta_key'] = '_auction_dates_to_time';
$args['meta_type'] = 'UNSIGNED';
$args['orderby'] = "meta_value";
$args['order'] = 'DESC';
$args['paged'] = $paged;
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['timer'] = 'Sort by Bid End Time: low to high';
$sortby['timer-desc'] = 'Sort by Bid End Time: high to low';
return $sortby;
}
Please HELP me on this issue.
Thanks