Woocomerce – Order products by float attribute in archive pages

OK… First of all, `$query->set( ‘orderby’, ‘pa_od’ );’ will most probably do nothing. You can’t order by some string and think that WordPress will guess what that is.

Here is the list of possible orderby values:

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

If you want to order by custom field, then you have to do it this way:

$query->set( 'meta_key', 'pa_od' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'ASC' );

And because you want to treat that meta value as number, then this is what you really want:

$query->set( 'meta_key', 'pa_od' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );

PS. Your function is an action, so you don’t need to return anything – the returned value will be ignored anyway… So here’s all the code:

add_action( 'woocommerce_product_query', 'imcar_custom_product_query' );
function imcar_custom_product_query( $query ) {

    if( ! $query->is_main_query() )
        return;

    $query->set( 'meta_key', 'pa_od' );
    $query->set( 'orderby', 'meta_value_num' );
    $query->set( 'order', 'ASC' );
}