products() public static method

List multiple products shortcode.
public static products ( array $atts ) : string
$atts array
return string
function wc_products_price_range($atts, $content, $shortcode)
{
    if (class_exists('WooCommerce')) {
        $shortcodes = new WC_Shortcodes();
        if (is_array($atts)) {
            $min = (int) $atts['min'];
            $max = (int) $atts['max'];
            if ($min && $max) {
                $and = "meta_value BETWEEN {$min} AND {$max}";
            } else {
                if ($min) {
                    $and = "meta_value >= {$min}";
                } elseif ($max) {
                    $and = "meta_value <= {$max}";
                }
            }
            if ($and) {
                global $wpdb;
                $query = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_price' AND {$and}";
                $ids = $wpdb->get_col($query);
                if (!empty($ids)) {
                    $atts['ids'] = implode(",", $ids);
                }
            }
        }
        return $shortcodes->products($atts);
    }
}