コード例 #1
0
    /**
     * Category selection
     */
    public function category_widget()
    {
        $categories = get_terms('product_cat', array('orderby' => 'name'));
        ?>
		<form method="GET">
			<div>
				<select multiple="multiple" data-placeholder="<?php 
        _e('Select categories&hellip;', 'jigoshop');
        ?>
" class="jigoshop-enhanced-select" id="show_categories" name="show_categories[]" style="width: 205px;">
					<?php 
        $r = array();
        $r['pad_counts'] = 1;
        $r['hierarchical'] = 1;
        $r['hide_empty'] = 1;
        $r['value'] = 'id';
        $r['selected'] = $this->show_categories;
        echo jigoshop_walk_category_dropdown_tree($categories, 0, $r);
        ?>
				</select>
				<a href="#" class="select_none"><?php 
        _e('None', 'jigoshop');
        ?>
</a>
				<a href="#" class="select_all"><?php 
        _e('All', 'jigoshop');
        ?>
</a>
				<input type="submit" class="submit button" value="<?php 
        _e('Show', 'jigoshop');
        ?>
" />
				<input type="hidden" name="range" value="<?php 
        if (!empty($_GET['range'])) {
            echo esc_attr($_GET['range']);
        }
        ?>
" />
				<input type="hidden" name="start_date" value="<?php 
        if (!empty($_GET['start_date'])) {
            echo esc_attr($_GET['start_date']);
        }
        ?>
" />
				<input type="hidden" name="end_date" value="<?php 
        if (!empty($_GET['end_date'])) {
            echo esc_attr($_GET['end_date']);
        }
        ?>
" />
				<input type="hidden" name="page" value="<?php 
        if (!empty($_GET['page'])) {
            echo esc_attr($_GET['page']);
        }
        ?>
" />
				<input type="hidden" name="tab" value="<?php 
        if (!empty($_GET['tab'])) {
            echo esc_attr($_GET['tab']);
        }
        ?>
" />
				<input type="hidden" name="report" value="<?php 
        if (!empty($_GET['report'])) {
            echo esc_attr($_GET['report']);
        }
        ?>
" />
			</div>
			<script type="text/javascript">
				jQuery(function($){
					// Select all/none
					$('.chart-widget')
						.on('click', '.select_all', function(){
							$(this).closest('div').find('select option').attr("selected", "selected");
							$(this).closest('div').find('select').change();
							return false;
						})
						.on('click', '.select_none', function(){
							$(this).closest('div').find('select option').removeAttr("selected");
							$(this).closest('div').find('select').change();
							return false;
						});
				});
			</script>
		</form>
		<?php 
    }
コード例 #2
0
/**
 * Jigoshop Dropdown categories
 *
 * @see http://core.trac.wordpress.org/ticket/13258
 * @param bool $show_counts
 * @param bool $hierarchal
 * @internal
 */
function jigoshop_product_dropdown_categories($show_counts = true, $hierarchal = true)
{
    global $wp_query;
    $r = array();
    $r['pad_counts'] = 1;
    $r['hierarchal'] = $hierarchal;
    $r['hide_empty'] = 1;
    $r['show_count'] = $show_counts;
    $r['selected'] = isset($wp_query->query['product_cat']) ? $wp_query->query['product_cat'] : '';
    $terms = get_terms('product_cat', $r);
    if (!$terms) {
        return;
    }
    $output = "<select name='product_cat' id='dropdown_product_cat'>";
    $output .= '<option value="" ' . selected(isset($_GET['product_cat']) ? esc_attr($_GET['product_cat']) : '', '', false) . '>' . __('View all categories', 'jigoshop') . '</option>';
    $output .= jigoshop_walk_category_dropdown_tree($terms, 0, $r);
    $output .= "</select>";
    echo $output;
}