Advertisement
palsushobhan

wcfm-hide-vendors-on-vacation-from-store-list

May 15th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. add_filter('wcfmmp_exclude_vendors_list', function($exclude_vendor_list) {
  2.     global $wpdb;
  3.     $vacation_args = array(
  4.         'role__in'   => apply_filters( 'wcfmmp_allwoed_vendor_user_roles', array( 'wcfm_vendor' ) ),
  5.         'meta_query' => array(
  6.             array(
  7.                 array(
  8.                     'key'     => 'wcfmmp_profile_settings',
  9.                     'value'   => ';s:18:"wcfm_vacation_mode";s:3:"yes";',
  10.                     'compare' => 'LIKE',
  11.                 ),
  12.                 array(
  13.                     'key'     => 'wcfmmp_profile_settings',
  14.                     'value'   => ';s:30:"wcfm_disable_vacation_purchase";s:3:"yes";',
  15.                     'compare' => 'LIKE',
  16.                 ),
  17.             ),
  18.         ),
  19.         'fields' => 'ID',
  20.     );
  21.     $on_vacation = get_users( $vacation_args );
  22.     $sql = "select user_id, meta_value from {$wpdb->prefix}usermeta where user_id IN (" . implode( ",", $on_vacation ) . ") AND meta_key = 'wcfmmp_profile_settings'";
  23.     $result = $wpdb->get_results($sql);
  24.     $exclude_vendor = [];
  25.     if( !empty( $result ) ) {
  26.         foreach ($result as $value) {
  27.             $settings = maybe_unserialize($value->meta_value);
  28.             if(isset($settings['wcfm_vacation_mode_type']) && 'instant' == $settings['wcfm_vacation_mode_type']) {
  29.                 $exclude_vendor[] = $value->user_id;
  30.                 continue;
  31.             }
  32.             $wcfm_vacation_start_date = isset($settings['wcfm_vacation_start_date']) ? $settings['wcfm_vacation_start_date'] : '';
  33.             $wcfm_vacation_end_date = isset($settings['wcfm_vacation_end_date']) ? $settings['wcfm_vacation_end_date'] : '';
  34.             if( $wcfm_vacation_start_date && $wcfm_vacation_end_date ) {
  35.                 $current_time = strtotime( 'midnight', current_time( 'timestamp' ) );
  36.                 $start_time = strtotime( $wcfm_vacation_start_date );
  37.                 $end_time = strtotime( $wcfm_vacation_end_date );
  38.                 if( ($current_time >= $start_time) && ($current_time <= $end_time) ) {
  39.                     $exclude_vendor[] = $value->user_id;
  40.                     continue;
  41.                 }
  42.             }
  43.         }
  44.         $exclude_vendor_list = array_unique(array_merge($exclude_vendor_list, $exclude_vendor));
  45.     }
  46.     return $exclude_vendor_list;
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement