Advertisement
businessdad

H.Rolands - Hide events that have not started

Nov 12th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. /**
  2.  * Hides products whose start date is in the past.
  3.  *
  4.  * @param bool visible The original visibility flag.
  5.  * @param int product_id The product ID.
  6.  * @return bool
  7.  * @author Aelia <support@aelia.co>
  8.  */
  9. add_filter('woocommerce_product_is_visible', function($visible, $product_id) {
  10.   $start_date = DateTime::createFromFormat('Ymd', trim(get_post_meta($product_id, 'start_date', true)));
  11.  
  12.   // If a valid start date was entered, the product is visible only if said
  13.   // start date has not yet been reached
  14.   if(!empty($start_date)) {
  15.     $today = new DateTime();
  16.     $visible = $today < $start_date;
  17.   }
  18.  
  19.   return $visible;
  20. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement