function productos_por_rango_precio( $atts ) {
$atts = shortcode_atts( array(
'min' => 0,
'max' => 999999,
'posts_per_page' => 12,
), $atts, 'productos_rango_precio' );
$args = array(
'post_type' => 'product',
'posts_per_page' => $atts['posts_per_page'],
'meta_query' => array(
array(
'key' => '_price',
'value' => array( $atts['min'], $atts['max'] ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
)
)
);
$query = new WP_Query( $args );
if ( ! $query->have_posts() ) {
return '<p>No se encontraron productos en este rango de precios.</p>';
}
ob_start();
while ( $query->have_posts() ) {
$query->the_post();
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode( 'productos_rango_precio', 'productos_por_rango_precio' );