/** * Returns field configs for tour search form. * * @param boolean $only_allowed_in_settings if set to true only fields allwed in Tours > Search Form > Additional Fields option. * @param boolean $clear_empty_values * @return array */ public static function get_search_form_fields_html($only_allowed_in_settings = true, $clear_empty_values = false) { $result = array(); $form_taxonomies = self::get_search_form_fields($only_allowed_in_settings); if (!$form_taxonomies) { return $result; } $tour_tax_request = isset($_REQUEST['tourtax']) ? $_REQUEST['tourtax'] : array(); foreach ($form_taxonomies as $name => $list) { if ('__tour_categories_filter' === $name) { if (!adventure_tours_check('tour_category_taxonomy_exists')) { continue; } $current_term_id = !empty($_REQUEST['tour_category']) ? $_REQUEST['tour_category'] : ''; /* // For WP < 4.3 $current_term_id = 0; $tour_cat_slug = ! empty( $_REQUEST['tour_category'] ) ? $_REQUEST['tour_category'] : ''; if ( $tour_cat_slug ) { $cur_cat_term = get_term_by( 'slug', $tour_cat_slug, 'tour_category' ); if ( $cur_cat_term ) { $current_term_id = $cur_cat_term->term_id; } }*/ $use_parent_cat_name_as_title = true; $parent_term_id = adventure_tours_get_option('tours_search_form_start_category'); $show_all_title = esc_html__('Category', 'adventure-tours'); if ($use_parent_cat_name_as_title && $parent_term_id) { $parent_term_obj = get_term($parent_term_id, 'tour_category'); if ($parent_term_obj) { $show_all_title = $parent_term_obj->name; } } $drop_down_html = wp_dropdown_categories(array('show_option_all' => $clear_empty_values ? ' ' : $show_all_title, 'hide_if_empty' => true, 'taxonomy' => 'tour_category', 'hierarchical' => true, 'echo' => false, 'name' => 'tour_category', 'value_field' => 'slug', 'hide_if_empty' => true, 'class' => 'selectpicker', 'show_count' => true, 'selected' => $current_term_id, 'child_of' => $parent_term_id)); if ($drop_down_html) { // to replace value='0' with value='' - as options with empty string value are hidhlighted with placeholder color only $drop_down_html = preg_replace('`(\\s+value=(?:\\"|\'))0(\\"|\')`', '$1$2', $drop_down_html); $icon_class = $parent_term_id ? AtTourHelper::get_tour_category_icon_class($parent_term_id) : ''; $result[] = array('icon' => $icon_class ? $icon_class : 'td-network', 'html' => $drop_down_html, 'label' => $show_all_title); } } else { $selected_value = isset($tour_tax_request[$name]) ? $tour_tax_request[$name] : ''; $attribute_title = wc_attribute_label($name); $list_options = array(); foreach ($list as $value => $title) { /*if ( $is_show_label ) { if ( $attribute_title == $title ) { continue; } }*/ if ($clear_empty_values && !$value) { $title = ' '; } $list_options[] = sprintf('<option value="%s"%s>%s</option>', esc_attr($value), $selected_value == $value ? ' selected="selected"' : '', esc_html($title)); } $result[] = array('icon' => AtTourHelper::get_product_attribute_icon_class($name), 'html' => '<select name="tourtax[' . esc_attr($name) . ']" class="selectpicker">' . join('', $list_options) . '</select>', 'label' => $attribute_title); } } return $result; }
public function get_fields_config($product) { $state_key = $this->make_product_state_key('base_fields_config', $product); $result = $this->get_state($state_key, false); if (false === $result) { $booking_dates = $this->get_booking_dates($product, true); $product_id = $product->id; /*if ( $product_id && adventure_tours_check('is_wpml_in_use') ) { $product_id = apply_filters( 'translate_object_id', $product_id, 'product', true, apply_filters( 'wpml_default_language', '' ) ); }*/ $result = array('add-to-cart' => array('type' => 'hidden', 'default' => $product_id)); $is_mutli_quantity_form = $this->is_mutli_quantity_form($product); if ($product->is_variable_tour()) { $variation_rules = array(); if (!$is_mutli_quantity_form) { $variation_rules[] = 'required'; } $variation_rules[] = 'variation_id'; $result['variation_id'] = array('type' => 'hidden', 'rules' => $variation_rules); $variation_attributes = $product->get_variation_attributes(); foreach ($variation_attributes as $attribute_name => $options) { $attrib_field_name = 'attribute_' . sanitize_title($attribute_name); $result[$attrib_field_name] = array('type' => 'variation_select', 'name' => $attrib_field_name, 'attribute' => $attribute_name, 'product' => $product, 'options' => $options, 'class' => 'selectpicker', 'label' => wc_attribute_label($attribute_name), 'default' => $product->get_variation_default_attribute($attribute_name), 'icon_class' => AtTourHelper::get_product_attribute_icon_class($attribute_name)); } } if ($booking_dates || !$this->hide_date_field_for_no_booking_dates) { $date_default_value = ''; if ($booking_dates) { $date_default_value = date($this->get_date_format(), strtotime(key($booking_dates))); } $date_label = esc_html__('Date', 'adventure-tours'); $result['date'] = array('label' => $date_label, 'placeholder' => $date_label, 'rules' => array('required', 'date', 'booking_date'), 'default' => $date_default_value, 'icon_class' => 'td-calendar'); // improvements required after testing is completed if ($booking_dates) { $date_options = array(); ksort($booking_dates); foreach ($booking_dates as $_date => $_open_tickets) { $date_options[$_date] = sprintf($this->date_field_text_format, $this->convert_date_for_human($_date), $_open_tickets); } $date_exact_field = array('type' => 'select', 'options' => $date_options); // $result['date_exact'] = $date_exact_field; $result['date'] = array_merge($result['date'], $date_exact_field); } } // quantity field should follow after booking date field, validation requirement $quantity_label = esc_html__('Quantity', 'adventure-tours'); $invalid_tickets_number = esc_html__('Please enter the amount of tickets.', 'adventure-tours'); if ($is_mutli_quantity_form) { $expand_attribute_name = $this->get_expand_quantity_attribute_name($product); $expand_field_key = $expand_attribute_name ? 'attribute_' . $expand_attribute_name : null; $default_expand_attribute_value = $product->get_variation_default_attribute($expand_attribute_name); $quantity_redirect_to = null; $quantity_fields_set = $this->get_quantity_field_expand_values($product); foreach ($quantity_fields_set as $field_suffix => $field_label) { $new_field_key = 'quantity_' . $field_suffix; $result['variation_id_' . $field_suffix] = array('type' => 'hidden'); // implement icon selection filter selection depends on attribute value $result[$new_field_key] = array('type' => 'number', 'label' => $field_label, 'placeholder' => $field_label, 'default' => '', 'icon_class' => 'td-users', 'attributes' => array('data-quantityattribute' => $expand_field_key, 'min' => '0'), 'rules' => array(array('type' => 'combined_ticket_number', 'message' => $invalid_tickets_number), 'combined_booking_tickets')); if ($field_suffix == $default_expand_attribute_value || !$quantity_redirect_to) { $quantity_redirect_to = $new_field_key; } } if ($quantity_redirect_to) { // complete icons selection $result[$quantity_redirect_to]['icon_class'] = 'td-user-plus'; $result[$quantity_redirect_to]['default'] = 1; $this->errors_movement['quantity'] = $quantity_redirect_to; unset($result[$expand_field_key]); } } else { $result['quantity'] = array('type' => 'number', 'label' => $quantity_label, 'placeholder' => $quantity_label, 'rules' => array('required', array('type' => 'number', 'min' => '1', 'message' => $invalid_tickets_number, 'min_message' => $invalid_tickets_number), 'booking_tickets'), 'attributes' => array('min' => '1'), 'default' => '1', 'icon_class' => 'td-user-plus'); } $this->set_state($state_key, $result); } return $result; }