Hello,
I am experiencing an issue with the “New Products” tab on my WooCommerce website using the WoodMart theme.
I have set orderby=”rand” in the shortcode [products_tab post_type=”new” orderby=”rand”], expecting the products to display in a random order each time the page is refreshed. However, the products appear in the same order every time, as if the rand parameter is being ignored.
After troubleshooting, I found that adding the following custom code to functions.php resolves the issue:
==========================================================================
function force_random_products_query( $query ) {
if ( isset( $query->query[‘post_type’] ) && $query->query[‘post_type’] == ‘product’ ) {
$query->set( ‘orderby’, ‘rand’ );
}
}
add_action( ‘pre_get_posts’, ‘force_random_products_query’ );
==========================================================================
This suggests that either the WoodMart theme or one of its included features may be overriding the default WooCommerce query settings.
Could you confirm whether this is a known issue with the theme? Is there a built-in setting or fix to allow orderby=”rand” to work correctly without needing custom PHP code?
Thank you for your support. I look forward to your response.
Best regards,