Home Forums WoodMart support forum Critical Issue with Product Sorting in Woodmart Product Grid Widget

Critical Issue with Product Sorting in Woodmart Product Grid Widget

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #713916

    peteris.naglis
    Participant

    Dear Woodmart Support Team,

    We are experiencing a critical database error when attempting to implement custom product sorting functionality on our WooCommerce store using the Woodmart “Edit Products (grid or carousel)” widget.

    **ISSUE DESCRIPTION:**
    When we try to modify the SQL ORDER BY clause to sort products by discount percentage, we receive the following error:

    “WordPress database error: [Unknown column ‘pm_discount.meta_value’ in ‘ORDER BY’]”

    **ERROR QUERY:**
    The failing query shows that the LEFT JOIN for the postmeta table is NOT being included in the final SQL query, even though we’ve properly added it via the posts_join filter. This causes the ORDER BY clause to reference a column that doesn’t exist in the query.

    **ROOT CAUSE:**
    It appears that the Woodmart product grid widget uses its own custom query builder (possibly via AJAX or a custom query handler) that:
    1. Does not respect the standard WordPress posts_orderby filter
    2. Does not properly merge JOINs added via the posts_join filter
    3. Pre-calculates the product ID list, then runs a separate query with WHERE … ID IN (…)

    This prevents any custom ORDER BY modifications from working correctly.

    **AFFECTED QUERY STRUCTURE:**
    `sql
    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM wp_posts
    WHERE 1=1
    AND wp_posts.ID IN (27818, 27819, 27820, …)
    AND wp_posts.post_type = ‘product’
    AND wp_posts.post_status = ‘publish’
    GROUP BY wp_posts.ID
    ORDER BY CAST(pm_discount.meta_value AS SIGNED) DESC
    — NOTE: No LEFT JOIN is present, so pm_discount.meta_value is undefined
    OUR ATTEMPTED SOLUTIONS: We have tried multiple approaches:

    Using posts_join and posts_orderby filters
    Using woocommerce_product_query_meta_query filter
    Using subqueries with COALESCE
    Using alternative meta_query approaches
    NONE of these work because the Woodmart widget appears to bypass these standard WordPress hooks.

    REQUEST: Could you please:

    Clarify which hooks/filters the Woodmart product grid widget respects for custom sorting
    Provide a documented method for implementing custom ORDER BY logic in product grids
    Or, consider fixing the widget to properly merge JOINs from custom filters
    WORKAROUND NEEDED: We need an alternative method to sort products by discount percentage within the Woodmart product grid widget that doesn’t rely on modifying the SQL query directly.

    Thank you for your assistance.

    Best regards, [Peteris Naglis]

    #713926

    Artem Temos
    Keymaster
    Xtemos team

    Hi Peteris,

    Thanks for the detailed report.

    The issue you’re seeing is tied to custom code that alters query parts and theme files. Customizations like this are outside our support scope.

    About the widget behavior and hooks:
    – WoodMart product grids and the Archive Products element use the standard WooCommerce sorting options available in the interface: popularity, price, name, rating, and date. There is no built-in option to sort by a custom metric like discount percentage.
    – There isn’t a documented hook in our product grid/widget to inject custom SQL JOINs or override ORDER BY logic for meta-based sorting. The widget does not provide a method to merge custom JOINs added via posts_join or to implement custom ORDER BY for discount percentage.
    – You can control which default options appear in the WooCommerce sorting dropdown with the woocommerce_catalog_orderby filter (for example, to remove unwanted options), but adding a fully custom meta-based sort to the grid via our widget isn’t supported.

    We don’t have a built-in workaround in the widget to sort by discount percentage. Implementing that would require custom development outside the theme’s standard options.

    Kind Regards

Viewing 2 posts - 1 through 2 (of 2 total)