Woocomerce – Order products by float attribute in archive pages

I’m trying to order the products in the frontend by a float attribute (pa_od), I have this code but the order is incorrect

add_action( ‘woocommerce_product_query’, ‘imcar_custom_product_query’ );
function imcar_custom_product_query( $query ) {

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

$query->set( ‘orderby’, ‘pa_od’ );
$query->set( ‘order’, ‘ASC’ );

return $query;
}

The order don’t are ASC, The first product have pa_od value 25, the second 12, the third 20.

Thanks

Read more here:: Woocomerce – Order products by float attribute in archive pages

Leave a Reply

Your email address will not be published. Required fields are marked *