WooCommerce Appointments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//WooCommerce Appointments, Date Filters applied to appointment start date class WOE_Filter_By_App_Date { var $from_date = ""; var $to_date = ""; function __construct() { add_filter('woe_settings_validate_defaults', function($settings){ if($settings['from_date']) { $this->from_date= $settings['from_date']; $settings['from_date'] = ""; } if($settings['to_date']) { $this->to_date= $settings['to_date']; $settings['to_date'] = ""; } return $settings; }); add_filter( 'woe_sql_get_order_ids_where', function($where, $settings ){ global $wpdb; $date_sql = ""; if ( $this->from_date OR $this->to_date) { $meta_val_filter = array(); if( $this->from_date ) $meta_val_filter[] = "CAST(meta_value AS UNSIGNED) >= ". date("YmdHis", strtotime($this->from_date. " 00:00:00")); if( $this->to_date ) $meta_val_filter[] = "CAST(meta_value AS UNSIGNED) <= ". date("YmdHis", strtotime($this->to_date. " 23:59:59")); $meta_val_filter = join( " AND ", $meta_val_filter); $date_sql = "AND ID IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_appointment_start' AND $meta_val_filter )"; } $where[] = "orders.ID IN (SELECT post_parent FROM $wpdb->posts WHERE post_type='wc_appointment' $date_sql)"; return $where; },10,2); } //end construct } new WOE_Filter_By_App_Date(); |