WooCommerce filter product by price

woocommerce_product_data_store_cpt_get_products_query
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', 'handle_price_range_query_var', 10, 2 );
function handle_price_range_query_var( $query, $query_vars ) {
    if ( ! empty( $query_vars['price_range'] ) ) {
        $price_range = explode( '|', esc_attr($query_vars['price_range']) );

        if ( is_array($price_range) && count($price_range) == 2 ) {
            $query['meta_query']['relation'] = 'AND';

            $query['meta_query'][] = array(
                'key'     => '_price',
                'value'   => reset($price_range), // From price value
                'compare' => '>=',
                'type'    => 'NUMERIC'
            );
            
            if( end($price_range) != ''){
                $query['meta_query'][] = array(
                    'key'     => '_price',
                    'value'   => end($price_range), // To price value
                    'compare' => '<=',
                    'type'    => 'NUMERIC'
                );
            }

            $query['orderby'] = 'meta_value_num'; // sort by price
            $query['order'] = 'ASC'; // In ascending order
        }
    }
    return $query;
}

thanks to