Home:ALL Converter>Add meta_type in custom sorting using woocommerce

Add meta_type in custom sorting using woocommerce

Ask Time:2014-10-20T13:56:30         Author:Hira Singh

Json Formatter

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

Author:Hira Singh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26459290/add-meta-type-in-custom-sorting-using-woocommerce
yy