Created
December 7, 2020 07:19
-
-
Save digamber89/4b43ae0cbb0841fceeef4e0b4afea027 to your computer and use it in GitHub Desktop.
Hide Past Meeting Products from Shop and Other Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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