200, // there shouldn't be more than 200 product 'post_type' => 'product', 'meta_query' => array( array( 'key' => '_booked_appointment', 'compare' => '=', 'value' => 'yes' ) ), 'suppress_filters' => false )); $options = array(); foreach ($products as $product) { $options[$product->ID] = apply_filters('the_title', $product->post_title); } self::$calls['products']['objects'] = $products; self::$calls['products']['options'] = $options; } return self::$calls['products']; } public static function get_calendar_page_info( $calendar_id = null ) { global $wpdb; $pages = false; $shortcode = '[booked-calendar'; if ( $calendar_id ) { $calendar_id = intval($calendar_id); $search_query = "`post_type` = 'page' AND `post_content` LIKE '%calendar={$calendar_id}%'"; $search_query .= " OR `post_type` = 'page' AND `post_content` LIKE '%calendar=\"{$calendar_id}\"%'"; $search_query .= ' OR `post_type` = "page" AND `post_content` LIKE "%calendar=\'{'.$calendar_id.'}\'%"'; $query = "SELECT * FROM `{$wpdb->posts}` WHERE ".$search_query; $pages = $wpdb->get_results($query); } if ( !$pages ) { $shortcode = '[booked-calendar'; $query = "SELECT * FROM `{$wpdb->posts}` WHERE `post_type` = 'page' AND `post_content` LIKE '{$shortcode}'"; $pages = $wpdb->get_results($query); } if (!$pages){ return; } // return the first found calendar return $pages[0]; } public static function get_login_page_info() { global $wpdb; $query = "SELECT * FROM `{$wpdb->posts}` WHERE `post_type` = 'page' AND `post_content` LIKE '%[booked-login]%'"; $pages = $wpdb->get_results($query); if ( !$pages ) { return; } // return the first found calendar return $pages[0]; } public static function get_appointments_page_info() { global $wpdb; $query = "SELECT * FROM `{$wpdb->posts}` WHERE `post_type` = 'page' AND `post_content` LIKE '%[booked-appointments]%'"; $pages = $wpdb->get_results($query); if ( !$pages ) { return; } // return the first found calendar return $pages[0]; } public static function booked_new_appointment_form() { if ( !empty($_POST['action']) && $_POST['action']==='booked_new_appointment_form' && !empty($_POST['source']) && $_POST['source']==='booked_wc_extension' ) { $booking_form = Booked_WC_Fragments::get_path('ajax-loaded/appointment', 'change-date'); include($booking_form); exit; } } public static function get_calendar_id_from_post_request() { $calendar_id = (isset($_POST['calendar_id']) ? $_POST['calendar_id'] : false); $calendar_id = array($calendar_id); $calendar_id = array_map( 'intval', $calendar_id ); $calendar_id = array_unique( $calendar_id ); if ( !empty($calendar_id) && is_numeric($calendar_id[0]) ) { return $calendar_id[0]; } return false; } public static function get_custom_fields() { $calendar_id = self::get_calendar_id_from_post_request(); $custom_fields = array(); if ( $calendar_id ) { $custom_fields_option_name = 'booked_custom_fields_' . $calendar_id; $custom_fields = json_decode(stripslashes(get_option($custom_fields_option_name)),true); } if ( !$custom_fields ) { $custom_fields = json_decode(stripslashes(get_option('booked_custom_fields')),true); } return $custom_fields; } // filtrates the custom field values before creating a new appointment public static function booked_custom_field_data( $custom_field_data = array() ) { // get custom fields $custom_fields = self::get_custom_fields(); if ( empty($custom_fields) ) { return $custom_field_data; } // handle the custom fields data $has_product = false; foreach($custom_fields as $key => $field) { $field_name = $field['name']; $field_parts = explode('---',$field_name); $field_type = $field_parts[0]; $field_marker = ''; if ( $field_type !== 'paid-service-label' ) { continue; } if ( !isset($_POST[$field_name]) || empty($_POST[$field_name]) ) { continue; } $field_title = $field['value']; $product_id = intval($_POST[$field_name]); $product = Booked_WC_Product::get($product_id); $end_of_string = explode('___',$field_parts[1]); $numbers_only = $end_of_string[0]; $is_required = (isset($end_of_string[1]) ? true : false); // set product title $custom_field_data[$key]['value'] = esc_html($product->title); $field_marker .= 'product_id::' . $product_id; $option_name = str_replace($field_type, 'paid-service-variation', $field_name); if ( isset($_POST[$option_name]) && !empty($_POST[$option_name]) ) { $variation_id = intval($_POST[$option_name]); if ( isset($product->variations[$variation_id]) ) { $variation_details = $product->variations[$variation_id]; $variation_title = $variation_details['variation_title']; // add variation value $custom_field_data[$key]['value'] .= '
[ ' . esc_html($variation_title) . ' ]'; $field_marker .= '|variation_id::' . $variation_id; } } // add a marker containing the product ID // simple-product -> product_id::ID // variable-product -> product_id::ID|variation_id::ID $custom_field_data[$key]['value'] .= ""; $has_product = true; } if ( $has_product ) { // check for a calendar assignee $calendar_id = self::get_calendar_id_from_post_request(); if ( $calendar_id ) { $term_meta = get_option( "taxonomy_{$calendar_id}" ); $assignee_email = $term_meta['notifications_user_id']; if ( $assignee_email && ($usr=get_user_by('email', $assignee_email)) ) { $custom_field_data['booking-agent'] = array( 'label' => esc_attr__('Booking Agent', 'booked-woocommerce-payments'), 'value' => $usr->display_name ); } } add_filter('booked_new_appointment_args', array('Booked_WC_Functions', 'booked_new_appointment_args_on_create'), 10, 1); } return $custom_field_data; } // filtrates the custom field values before creating a new appointment public static function booked_prepare_sending_reminder( $send = true, $appt_id = false ) { if ( empty( $appt_id ) ): return false; endif; if ( is_array( $appt_id ) ): return false; else: $custom_field_val = get_post_meta( $appt_id, '_cf_meta_value', true ); $is_wc_order = strpos( $custom_field_val, '