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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s