I’m trying to customize WooCommerce sorting: show featured products, then items added within the last 120 days, and finally sort the remainder by order and title. See code sample below.
try using a combined meta_query with your date_query within the pre_get_posts hook. maby expeirment with the order of your parameters to get a clearer result and avoid conflicts. even though it can be tricky, this method often gives more control
I attempted something similar on a project last year, and I recognized the importance of testing each query modification in isolation before combining them. I switched to a pre_get_posts approach where I initially filtered by featured items, then applied a second query to manage the date condition. This step-by-step approach made debugging easier. In my experience, separating concerns in the code rather than combining multiple filters often gives clearer results and avoids unexpected conflicts. Experimenting with indexes and ensuring values are correctly defined in your meta fields helped improve the overall query performance as well.
Having worked on similar WooCommerce customizations in the past, I found that mixing multiple criteria often requires special attention to how the queries are structured. Rather than lumping everything into one filter, I experimented with isolating the conditions within the pre_get_posts hook. Addressing the featured items separately from the time-based filtering allowed for more precise control over the final order. In my experience, ensuring that the meta keys are correctly defined and testing individual query components can save significant debugging time and lead to a more predictable sorting behavior.