Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query block: no “Featured” products filter or Price/Rating order options

  • Hi,

    I’m using the WooCommerce Product Carousel design from GP Awesome
    (https://gpawesome.com/demo/gp-awesome-woocomerce-product-carousel/)

    and I’d like to drive the carousel from featured products instead of editing the homepage each time.

    What I’m trying to do
    Use the Query block so the carousel shows only featured WooCommerce products.
    So I can manage what appears on the main page by marking products as “Featured” in WooCommerce (or by category), without editing the page content.

    Issues
    Featured products
    When I add a parameter to the Query block, there is no option to filter by “Featured” (WooCommerce stores this in the product_visibility taxonomy with the term “featured”).
    The taxonomy list doesn’t seem to include Product visibility, so I can’t select featured products.
    Could you add support for filtering by featured products (e.g. expose product_visibility taxonomy or a dedicated “Featured products” parameter)?
    Order by Price / Rating / Sales
    In the Query block’s “Order by” options I don’t see Price, Sales or Rating for products.
    It would be very helpful to have these for WooCommerce product queries (e.g. “Order by: Price” and “Order by: Rating”) so carousels can be sorted by price or popularity.

    Request
    A way to filter the Query block by featured products (and ideally by product visibility in general).
    Order by: Price, Sales and Order by: Rating (or equivalent) for product post type.

    Thank you for your help and for GenerateBlocks.

  • Hi there,

    The taxonomy you are referring to is set to hidden by Woocommerce, so GB can not pull it, unfortunately!

    Order by does not support post meta out of box.

    You will need to write custom PHP code to modify the query args.

    Here’s an example, so add the class featured-products to the query block, if you want the products to order by regular price in asc order, add class featured-price-asc to the query block too.

    Some other classes for the order:featured-price-desc, featured-sale-asc, featured-rating-desc, feel free to modify the code to add more order options.

    add_filter( 'generateblocks_query_wp_query_args', function( $args, $attributes ) {
        // Only apply if the Query Loop has one of our trigger classes
        if ( empty( $attributes['className'] ) ) {
            return $args;
        }
    
        $classes = $attributes['className'];
    
        // Base: Show only featured products (add this for any featured variant)
        if ( strpos( $classes, 'featured-products' ) !== false ||
             strpos( $classes, 'featured-price-asc' ) !== false ||
             strpos( $classes, 'featured-price-desc' ) !== false ||
             strpos( $classes, 'featured-sale-asc' ) !== false ||
             strpos( $classes, 'featured-rating-desc' ) !== false ) {
    
            // Add tax_query for featured term
            $args['tax_query'][] = array(
                'taxonomy' => 'product_visibility',
                'field'    => 'name',     // or 'slug'
                'terms'    => 'featured',
                'operator' => 'IN',
            );
        }
    
        // Ordering examples - add more conditions based on classes
        if ( strpos( $classes, 'featured-price-asc' ) !== false ) {
            // Order by regular price ascending (lowest to highest)
            $args = array_merge( $args, array(
                'meta_key'     => '_regular_price',
                'orderby'      => 'meta_value_num',  // numeric sort
                'order'        => 'ASC',
                'meta_type'    => 'DECIMAL',         // optional but good for prices
            ) );
        }
    
        if ( strpos( $classes, 'featured-price-desc' ) !== false ) {
            // Order by regular price descending (highest to lowest)
            $args = array_merge( $args, array(
                'meta_key'     => '_regular_price',
                'orderby'      => 'meta_value_num',
                'order'        => 'DESC',
            ) );
        }
    
        if ( strpos( $classes, 'featured-sale-asc' ) !== false ) {
            // Order by sale price ascending (cheapest sale first)
            // Note: Only sale-enabled products have _sale_price; others fall back or sort oddly
            $args = array_merge( $args, array(
                'meta_key'     => '_sale_price',
                'orderby'      => 'meta_value_num',
                'order'        => 'ASC',
                'meta_type'    => 'DECIMAL',
            ) );
        }
    
        if ( strpos( $classes, 'featured-rating-desc' ) !== false ) {
            // Order by average rating descending (highest rated first)
            // WooCommerce stores average rating in _wc_average_rating meta
            $args = array_merge( $args, array(
                'meta_key'     => '_wc_average_rating',
                'orderby'      => 'meta_value_num',
                'order'        => 'DESC',
                'meta_type'    => 'DECIMAL',
            ) );
        }
    
        return $args;
    }, 10, 2 );
  • Thanks for the code, I will try asap.

    but I am not sure if I understand correctly.
    These features I have asked are already there for woocommerce for a while.
    There are tons of options to choose products.
    https://woocommerce.com/document/woocommerce-store-editing/customizing-shop-page-catalog/product-collection-block/

  • These are WooCommerce blocks; feel free to use them instead of using GB’s query block.

  • Hi Ying,
    Yes I know. But they are slow 🙂 adding 0.6 seconds to my page.
    thus I am trying to use your blocks but it is limited.

    I wish you can add some more woocommerce related features in the GB and GP.

    thanks

  • You are welcome   🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.