Skip to content

Instantly share code, notes, and snippets.

@digamber89
Created December 7, 2020 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digamber89/4b43ae0cbb0841fceeef4e0b4afea027 to your computer and use it in GitHub Desktop.
Save digamber89/4b43ae0cbb0841fceeef4e0b4afea027 to your computer and use it in GitHub Desktop.
Hide Past Meeting Products from Shop and Other Pages
<?php
function cm_exclude_past_meeting_products( $q ) {
$args = [
'post_type' => 'zoom-meetings',
'posts_per_page' => - 1,
'meta_query' => [
'relation' => 'AND',
[
'key' => '_meeting_field_start_date_utc',
'value' => vczapi_dateConverter( 'now', 'UTC', 'Y-m-d H:i:s', false ),
'compare' => '<=',
'type' => 'DATETIME'
],
[
'key' => '_vczapi_zoom_product_id',
'compare' => 'exists'
]
]
];
$past_meetings = new WP_Query( $args );
$past_meeting_product_ids = [];
if ( $past_meetings->have_posts() ) {
while ( $past_meetings->have_posts() ): $past_meetings->the_post();
$past_meeting_product_ids[] = get_post_meta( get_the_ID(), '_vczapi_zoom_product_id', true );
endwhile;
}
if ( ! empty( $past_meeting_product_ids ) ) {
$past_meeting_product_ids = array_unique( $past_meeting_product_ids );
$q->set( 'post__not_in', $past_meeting_product_ids );
}
}
add_action( 'woocommerce_product_query', 'cm_exclude_past_meeting_products' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment