• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_walk_category_dropdown_tree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_walk_category_dropdown_tree函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_walk_category_dropdown_tree函数的具体用法?PHP wc_walk_category_dropdown_tree怎么用?PHP wc_walk_category_dropdown_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wc_walk_category_dropdown_tree函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: wc_product_dropdown_categories

/**
 * WooCommerce Dropdown categories.
 *
 * Stuck with this until a fix for https://core.trac.wordpress.org/ticket/13258.
 * We use a custom walker, just like WordPress does.
 *
 * @param int $deprecated_show_uncategorized (default: 1)
 * @return string
 */
function wc_product_dropdown_categories($args = array(), $deprecated_hierarchical = 1, $deprecated_show_uncategorized = 1, $deprecated_orderby = '')
{
    global $wp_query;
    if (!is_array($args)) {
        _deprecated_argument('wc_product_dropdown_categories()', '2.1', 'show_counts, hierarchical, show_uncategorized and orderby arguments are invalid - pass a single array of values instead.');
        $args['show_count'] = $args;
        $args['hierarchical'] = $deprecated_hierarchical;
        $args['show_uncategorized'] = $deprecated_show_uncategorized;
        $args['orderby'] = $deprecated_orderby;
    }
    $current_product_cat = isset($wp_query->query_vars['product_cat']) ? $wp_query->query_vars['product_cat'] : '';
    $defaults = array('pad_counts' => 1, 'show_count' => 1, 'hierarchical' => 1, 'hide_empty' => 1, 'show_uncategorized' => 1, 'orderby' => 'name', 'selected' => $current_product_cat, 'menu_order' => false);
    $args = wp_parse_args($args, $defaults);
    if ('order' === $args['orderby']) {
        $args['menu_order'] = 'asc';
        $args['orderby'] = 'name';
    }
    $terms = get_terms('product_cat', apply_filters('wc_product_dropdown_categories_get_terms_args', $args));
    if (empty($terms)) {
        return;
    }
    $output = "<select name='product_cat' class='dropdown_product_cat'>";
    $output .= '<option value="" ' . selected($current_product_cat, '', false) . '>' . __('Select a category', 'woocommerce') . '</option>';
    $output .= wc_walk_category_dropdown_tree($terms, 0, $args);
    if ($args['show_uncategorized']) {
        $output .= '<option value="0" ' . selected($current_product_cat, '0', false) . '>' . __('Uncategorized', 'woocommerce') . '</option>';
    }
    $output .= "</select>";
    echo $output;
}
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:39,代码来源:wc-term-functions.php


示例2: category_widget

    /**
     * Category selection
     * @return void
     */
    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;', 'woocommerce');
        ?>
" class="chosen_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;
        include_once WC()->plugin_path() . '/includes/walkers/class-product-cat-dropdown-walker.php';
        echo wc_walk_category_dropdown_tree($categories, 0, $r);
        ?>
				</select>
				<a href="#" class="select_none"><?php 
        _e('None', 'woocommerce');
        ?>
</a>
				<a href="#" class="select_all"><?php 
        _e('All', 'woocommerce');
        ?>
</a>
				<input type="submit" class="submit button" value="<?php 
        _e('Show', 'woocommerce');
        ?>
" />
				<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(){
					jQuery("select.chosen_select").chosen();

					// Select all/none
					jQuery( '.chart-widget' ).on( 'click', '.select_all', function() {
						jQuery(this).closest( 'div' ).find( 'select option' ).attr( "selected", "selected" );
						jQuery(this).closest( 'div' ).find('select').trigger( 'chosen:updated' );
						return false;
					});

					jQuery( '.chart-widget').on( 'click', '.select_none', function() {
						jQuery(this).closest( 'div' ).find( 'select option' ).removeAttr( "selected" );
						jQuery(this).closest( 'div' ).find('select').trigger( 'chosen:updated' );
						return false;
					});
				});
			</script>
		</form>
		<?php 
    }
开发者ID:dabodude,项目名称:woocommerce,代码行数:95,代码来源:class-wc-report-sales-by-category.php


示例3: woocommerce_walk_category_dropdown_tree

function woocommerce_walk_category_dropdown_tree()
{
    return wc_walk_category_dropdown_tree();
}
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:4,代码来源:wc-deprecated-functions.php


示例4: woocommerce_walk_category_dropdown_tree

/**
 * @deprecated
 */
function woocommerce_walk_category_dropdown_tree($a1 = '', $a2 = '', $a3 = '')
{
    return wc_walk_category_dropdown_tree($a1, $a2, $a3);
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:7,代码来源:wc-deprecated-functions.php


示例5: aiwoo_shortcode_productcat

function aiwoo_shortcode_productcat($atts, $content = null)
{
    global $woocommerce, $wp_query, $post;
    $atts = shortcode_atts(array("show_count" => 0, "hierarchical" => 0, "show_children_only" => 0, "dropdown" => 0, "hide_empty" => 0, "orderby" => "order"), $atts);
    $c = $atts['show_count'];
    $h = $atts['hierarchical'];
    $s = $atts['show_children_only'];
    $d = $atts['dropdown'];
    $e = $atts['hide_empty'];
    $o = $atts['orderby'];
    $dropdown_args = array('hide_empty' => $e);
    $list_args = array('show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'product_cat', 'hide_empty' => $e);
    // Menu Order
    $list_args['menu_order'] = false;
    if ($o == 'order') {
        $list_args['menu_order'] = 'asc';
    } else {
        $list_args['orderby'] = 'title';
    }
    // Setup Current Category
    $current_cat = false;
    $cat_ancestors = array();
    if (is_tax('product_cat')) {
        $current_cat = $wp_query->queried_object;
        $cat_ancestors = get_ancestors($current_cat->term_id, 'product_cat');
    } elseif (is_singular('product')) {
        $product_category = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent'));
        if ($product_category) {
            $current_cat = end($product_category);
            $cat_ancestors = get_ancestors($current_cat->term_id, 'product_cat');
        }
    }
    // Show Siblings and Children Only
    if ($s && $current_cat) {
        // Top level is needed
        $top_level = get_terms('product_cat', array('fields' => 'ids', 'parent' => 0, 'hierarchical' => true, 'hide_empty' => false));
        // Direct children are wanted
        $direct_children = get_terms('product_cat', array('fields' => 'ids', 'parent' => $current_cat->term_id, 'hierarchical' => true, 'hide_empty' => false));
        // Gather siblings of ancestors
        $siblings = array();
        if ($cat_ancestors) {
            foreach ($cat_ancestors as $ancestor) {
                $ancestor_siblings = get_terms('product_cat', array('fields' => 'ids', 'parent' => $ancestor, 'hierarchical' => false, 'hide_empty' => false));
                $siblings = array_merge($siblings, $ancestor_siblings);
            }
        }
        if ($h) {
            $include = array_merge($top_level, $cat_ancestors, $siblings, $direct_children, array($current_cat->term_id));
        } else {
            $include = array_merge($direct_children);
        }
        $dropdown_args['include'] = implode(',', $include);
        $list_args['include'] = implode(',', $include);
        if (empty($include)) {
            return;
        }
    } elseif ($s) {
        $dropdown_args['depth'] = 1;
        $dropdown_args['child_of'] = 0;
        $dropdown_args['hierarchical'] = 1;
        $list_args['depth'] = 1;
        $list_args['child_of'] = 0;
        $list_args['hierarchical'] = 1;
    }
    // Dropdown
    if ($d) {
        $dropdown_defaults = array('show_counts' => $c, 'hierarchical' => $h, 'show_uncategorized' => 0, 'orderby' => $o, 'selected' => $current_cat ? $current_cat->slug : '');
        $dropdown_args = wp_parse_args($dropdown_args, $dropdown_defaults);
        //wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', $dropdown_args ) );
        $current_product_cat = isset($wp_query->query['product_cat']) ? $wp_query->query['product_cat'] : '';
        $terms = get_terms('product_cat', apply_filters('wc_product_dropdown_categories_get_terms_args', $dropdown_args));
        if (!$terms) {
            return;
        }
        $content = $content != '' ? $content : __('Select a category');
        $cat_drop = "<select name='product_cat' class='dropdown_product_cat'>";
        $cat_drop .= '<option value="" ' . selected($current_product_cat, '', false) . '>' . $content . '</option>';
        $cat_drop .= wc_walk_category_dropdown_tree($terms, 0, $dropdown_args);
        $cat_drop .= "</select>";
        wc_enqueue_js("\n\t\t\tjQuery('.dropdown_product_cat').change(function(){\n\t\t\t\tif(jQuery(this).val() != '') {\n\t\t\t\t\tlocation.href = '" . home_url() . "/?product_cat=' + jQuery(this).val();\n\t\t\t\t}\n\t\t\t});\n\t\t");
        return $cat_drop;
        // List
    } else {
        $list_args['echo'] = 0;
        $list_args['title_li'] = '';
        $list_args['pad_counts'] = 1;
        $list_args['show_option_none'] = __('No product categories exist.', 'woocommerce');
        $list_args['current_category'] = $current_cat ? $current_cat->term_id : '';
        $list_args['current_category_ancestors'] = $cat_ancestors;
        $content = $content != '' ? $content : __('Product Categories');
        $cat_list = '<h2 class="categories-title">' . $content . '</h2>';
        $cat_list .= '<ul class="product-categories">';
        $cat_list .= wp_list_categories(apply_filters('woocommerce_product_categories_widget_args', $list_args));
        $cat_list .= '</ul>';
        return $cat_list;
    }
}
开发者ID:ericvyc,项目名称:mtp,代码行数:97,代码来源:frontend.inc.php



注:本文中的wc_walk_category_dropdown_tree函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wcache函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_update_product_stock_status函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap