0

I'm trying to order the products in woocomerce archives pages by 3 custom fieds, my code is:

add_action( 'woocommerce_product_query', 'imcar_custom_product_query' );
function imcar_custom_product_query( $query ) {
    if( ! $query->is_main_query() )
        return;

    $meta_query = array(
        array(
            'ordern_d_clause' => array(
                'key' => 'ordern_d',
                 'type' => 'numeric',
                'compare' => '>='
            )
        ),
        array(
            'orden_ln_clause' => array(
                'key' => 'orden_ln',
                 'type' => 'numeric',
                'compare' => '>='
            )
        ),
        array(
            'orden_r_clause' => array(
                'key' => 'orden_r',
                 'type' => 'numeric',
                'compare' => '>='
            )
        )
    );

    $query->set('meta_query', $meta_query);
    $query->set('orderby', array('ordern_d_clause' => 'ASC', 'orden_ln_clause' => 'ASC', 'orden_r_clause' => 'ASC'));
}

But the products don't order correctly ASC, the second product have less order_d number than the first.

Attach image.

enter image description here

Can anyone help me?

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.