Woocommerce custom attributes as a values for price range

Trying to modify existing woocommerce price slider for sorting on custom attribute value not by price, but stuck at modding sql query.

Here is a part of standard woocommerce price query to sql, but modified for getting one custom attribute ranges:

    $sql  = "SELECT min( FLOOR( post_meta.meta_value ) ) as min_maxcarry, max( CEILING( post_meta.meta_value ) ) as max_maxcarry FROM {$wpdb->posts} ";
    $sql .= " LEFT JOIN {$wpdb->postmeta} as post_meta ON {$wpdb->posts}.ID = post_meta.post_id " . $meta_query_sql['join'];
    $sql .= "   WHERE {$wpdb->posts}.post_type IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_post_type', array( 'product' ) ) ) ) . "')
                AND {$wpdb->posts}.post_status = 'publish'
                AND post_meta.meta_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_post_type', array( '_maxcarry' ) ) ) ) . "')
                AND post_meta.meta_value > '' ";
    $sql .= $meta_query_sql['where'];
    var_dump( $sql );
    return $wpdb->get_row( $sql );

Anyone can help with it or suggest another way to show this slider? thanks in advance

Read more here: Woocommerce custom attributes as a values for price range

Leave a Reply

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