Modifying the WooCommerce Product Query for Product Loop

How to change what products show up in the shop loop ?

Add this to your theme's functions.php or any plugin file.


add_action( 'woocommerce_product_query', 'show_active_events_only' );

function show_active_events_only( $q ){
$todays_date = date(‘Y-m-d’, time());
$meta_query = $q->get( ‘meta_query’ );
$meta_query[] = array(
‘key’ => ‘wcv_custom_product_enddate’,
‘value’ => $todays_date,
‘compare’ => ‘>=’
);

$q->set( ‘meta_query’, $meta_query );
}

Advertisements