Ejemplo n.º 1
0
 /**
  * Print terms for the element selected
  *
  * @access public
  * @return void
  * @since 1.0.0
  */
 public function ajax_print_terms()
 {
     $type = $_POST['value'];
     $attribute = $_POST['attribute'];
     $return = array('message' => '', 'content' => $_POST);
     $terms = get_terms('pa_' . $attribute, array('hide_empty' => '0'));
     $return['content'] = yith_wcan_attributes_table($type, $attribute, $_POST['id'], $_POST['name'], json_decode($_POST['value']), false);
     echo json_encode($return);
     die;
 }
 /**
  * Print terms for the element selected
  *
  * @access public
  * @return void
  * @since 1.0.0
  */
 public function ajax_print_terms()
 {
     $type = $_POST['value'];
     $attribute = $_POST['attribute'];
     $return = array('message' => '', 'content' => $_POST);
     $terms = get_terms('pa_' . $attribute, array('hide_empty' => '0'));
     $settings = $this->get_settings();
     $widget_settings = $settings[$this->number];
     $value = '';
     if ('label' == $type) {
         $value = $widget_settings['labels'];
     } elseif ('color' == $type) {
         $value = $widget_settings['colors'];
     } elseif ('multicolor' == $type) {
         $value = $widget_settings['multicolor'];
     }
     if ($type) {
         $return['content'] = yith_wcan_attributes_table($type, $attribute, $_POST['id'], $_POST['name'], $value, false);
     }
     echo json_encode($return);
     die;
 }
        function form($instance)
        {
            global $woocommerce;
            $defaults = array('title' => '', 'attribute' => '', 'query_type' => 'and', 'type' => 'list', 'colors' => '', 'labels' => '', 'display' => 'all');
            $instance = wp_parse_args((array) $instance, $defaults);
            ?>

    <p>
        <label>
            <strong><?php 
            _e('Title', 'yit');
            ?>
:</strong><br />
            <input class="widefat" type="text" id="<?php 
            echo $this->get_field_id('title');
            ?>
" name="<?php 
            echo $this->get_field_name('title');
            ?>
" value="<?php 
            echo $instance['title'];
            ?>
" />
        </label>
    </p>

    <p>
        <label for="<?php 
            echo $this->get_field_id('attribute');
            ?>
"><strong><?php 
            _e('Attribute:', 'yit');
            ?>
</strong></label>
        <select class="yith_wcan_attributes widefat" id="<?php 
            echo esc_attr($this->get_field_id('attribute'));
            ?>
" name="<?php 
            echo esc_attr($this->get_field_name('attribute'));
            ?>
">
            <?php 
            yith_wcan_dropdown_attributes($instance['attribute']);
            ?>
        </select></p>

    <p><label for="<?php 
            echo $this->get_field_id('query_type');
            ?>
"><?php 
            _e('Query Type:', 'yit');
            ?>
</label>
        <select id="<?php 
            echo esc_attr($this->get_field_id('query_type'));
            ?>
" name="<?php 
            echo esc_attr($this->get_field_name('query_type'));
            ?>
">
            <option value="and" <?php 
            selected($instance['query_type'], 'and');
            ?>
><?php 
            _e('AND', 'yit');
            ?>
</option>
            <option value="or" <?php 
            selected($instance['query_type'], 'or');
            ?>
><?php 
            _e('OR', 'yit');
            ?>
</option>
        </select></p>

    <p><label for="<?php 
            echo $this->get_field_id('type');
            ?>
"><strong><?php 
            _e('Type:', 'yit');
            ?>
</strong></label>
        <select class="yith_wcan_type widefat" id="<?php 
            echo esc_attr($this->get_field_id('type'));
            ?>
" name="<?php 
            echo esc_attr($this->get_field_name('type'));
            ?>
">
            <option value="list" <?php 
            selected('list', $instance['type']);
            ?>
><?php 
            _e('List', 'yit');
            ?>
</option>
            <option value="color" <?php 
            selected('color', $instance['type']);
            ?>
><?php 
            _e('Color', 'yit');
            ?>
</option>
            <option value="label" <?php 
            selected('label', $instance['type']);
            ?>
><?php 
            _e('Label', 'yit');
            ?>
</option>
            <option value="select" <?php 
            selected('select', $instance['type']);
            ?>
><?php 
            _e('Dropdown', 'yit');
            ?>
</option>
        </select>
    </p>

    <p id="yit-wcan-display" class="yit-wcan-display-<?php 
            echo $instance['type'];
            ?>
">
        <label for="<?php 
            echo $this->get_field_id('display');
            ?>
"><strong><?php 
            _e('Display (default All):', 'yit');
            ?>
</strong></label>
        <select class="yith_wcan_type widefat" id="<?php 
            echo esc_attr($this->get_field_id('display'));
            ?>
" name="<?php 
            echo esc_attr($this->get_field_name('display'));
            ?>
">
            <option value="all"          <?php 
            selected('all', $instance['display']);
            ?>
>          <?php 
            _e('All (no hierarchical)', 'yit');
            ?>
</option>
            <option value="hierarchical" <?php 
            selected('hierarchical', $instance['display']);
            ?>
> <?php 
            _e('All Hierarchical', 'yit');
            ?>
   </option>
            <option value="parent"       <?php 
            selected('parent', $instance['display']);
            ?>
>       <?php 
            _e('Only Parent', 'yit');
            ?>
        </option>
        </select>
    </p>

    <div class="yith_wcan_placeholder">
        <?php 
            yith_wcan_attributes_table($instance['type'], $instance['attribute'], 'widget-' . $this->id . '-', 'widget-' . $this->id_base . '[' . $this->number . ']', $instance['type'] == 'color' ? $instance['colors'] : ($instance['type'] == 'label' ? $instance['labels'] : array()), $instance['display']);
            ?>
    </div>
    <span class="spinner" style="display: none;"></span>

<input type="hidden" name="widget_id" value="widget-<?php 
            echo $this->id;
            ?>
-" />
<input type="hidden" name="widget_name" value="widget-<?php 
            echo $this->id_base;
            ?>
[<?php 
            echo $this->number;
            ?>
]" />

    <script>jQuery(document).trigger('yith_colorpicker');</script>
<?php 
        }