本文整理汇总了PHP中wc_attribute_orderby函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_attribute_orderby函数的具体用法?PHP wc_attribute_orderby怎么用?PHP wc_attribute_orderby使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_attribute_orderby函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wc_get_product_terms
/**
* Wrapper for wp_get_post_terms which supports ordering by parent.
*
* NOTE: At this point in time, ordering by menu_order for example isn't possible with this function. wp_get_post_terms has no
* filters which we can utilise to modify it's query. https://core.trac.wordpress.org/ticket/19094
*
* @param int $product_id
* @param string $taxonomy
* @param array $args
* @return array
*/
function wc_get_product_terms($product_id, $taxonomy, $args = array())
{
if (!taxonomy_exists($taxonomy)) {
return array();
}
if (empty($args['orderby']) && taxonomy_is_product_attribute($taxonomy)) {
$args['orderby'] = wc_attribute_orderby($taxonomy);
}
// Support ordering by parent
if (!empty($args['orderby']) && $args['orderby'] == 'parent') {
$fields = isset($args['fields']) ? $args['fields'] : 'all';
// Unset for wp_get_post_terms
unset($args['orderby']);
unset($args['fields']);
$terms = wp_get_post_terms($product_id, $taxonomy, $args);
usort($terms, '_wc_get_product_terms_parent_usort_callback');
switch ($fields) {
case 'names':
$terms = wp_list_pluck($terms, 'name');
break;
case 'ids':
$terms = wp_list_pluck($terms, 'term_id');
break;
case 'slugs':
$terms = wp_list_pluck($terms, 'slug');
break;
}
} else {
$terms = wp_get_post_terms($product_id, $taxonomy, $args);
}
return $terms;
}
示例2: wc_get_product_terms
/**
* Wrapper for wp_get_post_terms which supports ordering by parent.
*
* NOTE: At this point in time, ordering by menu_order for example isn't possible with this function. wp_get_post_terms has no.
* filters which we can utilise to modify it's query. https://core.trac.wordpress.org/ticket/19094.
*
* @param int $product_id
* @param string $taxonomy
* @param array $args
* @return array
*/
function wc_get_product_terms($product_id, $taxonomy, $args = array())
{
if (!taxonomy_exists($taxonomy)) {
return array();
}
if (empty($args['orderby']) && taxonomy_is_product_attribute($taxonomy)) {
$args['orderby'] = wc_attribute_orderby($taxonomy);
}
// Support ordering by parent
if (!empty($args['orderby']) && in_array($args['orderby'], array('name_num', 'parent'))) {
$fields = isset($args['fields']) ? $args['fields'] : 'all';
$orderby = $args['orderby'];
// Unset for wp_get_post_terms
unset($args['orderby']);
unset($args['fields']);
$terms = wp_get_post_terms($product_id, $taxonomy, $args);
switch ($orderby) {
case 'name_num':
usort($terms, '_wc_get_product_terms_name_num_usort_callback');
break;
case 'parent':
usort($terms, '_wc_get_product_terms_parent_usort_callback');
break;
}
switch ($fields) {
case 'names':
$terms = wp_list_pluck($terms, 'name');
break;
case 'ids':
$terms = wp_list_pluck($terms, 'term_id');
break;
case 'slugs':
$terms = wp_list_pluck($terms, 'slug');
break;
}
} elseif (!empty($args['orderby']) && 'menu_order' === $args['orderby']) {
// wp_get_post_terms doesn't let us use custom sort order
$args['include'] = wp_get_post_terms($product_id, $taxonomy, array('fields' => 'ids'));
if (empty($args['include'])) {
$terms = array();
} else {
// This isn't needed for get_terms
unset($args['orderby']);
// Set args for get_terms
$args['menu_order'] = isset($args['order']) ? $args['order'] : 'ASC';
$args['hide_empty'] = isset($args['hide_empty']) ? $args['hide_empty'] : 0;
$args['fields'] = isset($args['fields']) ? $args['fields'] : 'names';
// Ensure slugs is valid for get_terms - slugs isn't supported
$args['fields'] = 'slugs' === $args['fields'] ? 'id=>slug' : $args['fields'];
$terms = get_terms($taxonomy, $args);
}
} else {
$terms = wp_get_post_terms($product_id, $taxonomy, $args);
}
return apply_filters('woocommerce_get_product_terms', $terms, $product_id, $taxonomy, $args);
}
示例3: wcva_load_dropdown_select
function wcva_load_dropdown_select($name, $options, $selected_value)
{
wcva_load_radio_select($name, $options, $selected_value, $hidden = true);
?>
<select id="<?php
echo esc_attr(sanitize_title($name));
?>
" name="attribute_<?php
echo sanitize_title($name);
?>
">
<option value=""><?php
echo __('Choose an option', 'woocommerce');
?>
…</option>
<?php
// Get terms if this is a taxonomy - ordered
if (taxonomy_exists(sanitize_title($name))) {
$orderby = wc_attribute_orderby(sanitize_title($name));
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC', 'hide_empty' => false);
break;
}
$terms = get_terms(sanitize_title($name), $args);
foreach ($terms as $term) {
if (!in_array($term->slug, $options)) {
continue;
}
echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($selected_value), sanitize_title($term->slug), false) . '>' . apply_filters('woocommerce_variation_option_name', $term->name) . '</option>';
}
} else {
foreach ($options as $option) {
echo '<option value="' . esc_attr(sanitize_title($option)) . '" ' . selected(sanitize_title($selected_value), sanitize_title($option), false) . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
}
}
?>
</select>
<?php
}
示例4: wc_bundles_get_product_terms
function wc_bundles_get_product_terms($product_id, $attribute_name, $args)
{
if (WC_PB_Core_Compatibility::is_wc_version_gte_2_3()) {
return wc_get_product_terms($product_id, $attribute_name, $args);
} else {
$orderby = wc_attribute_orderby(sanitize_title($attribute_name));
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC');
break;
}
$terms = get_terms(sanitize_title($attribute_name), $args);
return $terms;
}
}
示例5: get_variation_items
private function get_variation_items($attribute_name, $options, $grid_item_layout = 'vertical', $columns = 3)
{
$orderby = wc_attribute_orderby($attribute_name);
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC', 'hide_empty' => false);
break;
}
$terms = get_terms($attribute_name, $args);
ob_start();
if (isset($terms->errors)) {
?>
<div class="column"><?php
printf(__('No attributes found for this taxonomy. Be sure that they are visible on the product page and you created them via the <a href="%s" target="_blank">Attributes admin page</a>.'), admin_url() . 'edit.php?post_type=product&page=product_attributes');
?>
</div>
<?php
return false;
}
foreach ($terms as $term) {
if (!in_array($term->slug, $options)) {
continue;
}
$fpd_params = '';
$fpd_thumbnail = '';
if (class_exists('FPD_Parameters')) {
$fpd_params = get_option('mspc_variation_fpd_params_' . $term->term_id, '');
$fpd_params_array = array();
if (!empty($fpd_params)) {
if (strpos($fpd_params, 'enabled') !== false) {
//convert string to array
parse_str($fpd_params, $fpd_params_array);
$fpd_params = FPD_Parameters::convert_parameters_to_string($fpd_params_array);
}
}
$fpd_thumbnail = get_option('mspc_variation_fpd_thumbnail_' . $term->term_id, '');
}
$image_html = '';
$image_url = get_option('mspc_variation_image_' . $term->term_id);
if ($image_url !== false && !empty($image_url)) {
$image_id = $this->get_image_id($image_url);
$stage_image = wp_get_attachment_image_src($image_id, empty($fpd_params) ? 'shop_single' : 'full');
$image_thumb = empty($fpd_thumbnail) ? $stage_image[0] : $fpd_thumbnail;
$image_html = '<img src="' . $image_thumb . '" alt="' . $term->name . '" class="mspc-attribute-image rounded ui image" />';
}
$description_html = '';
if (!empty($term->description)) {
$description_html = '<p>' . $term->description . '</p>';
}
if ($grid_item_layout == 'vertical') {
?>
<div class="mspc-variation mspc-vertical column" data-parameters='<?php
echo $fpd_params;
?>
' data-image='<?php
echo $stage_image[0];
?>
'>
<div class="mspc-clearfix">
<div class="mspc-radio ui radio checkbox">
<input type="radio" name="<?php
echo $attribute_name;
?>
" value="<?php
echo esc_attr($term->slug);
?>
">
<label></label>
</div>
<?php
echo $image_html;
?>
<div class="mspc-text-wrapper">
<strong class="mspc-attribute-title"><?php
echo $term->name;
?>
</strong>
<?php
echo $description_html;
?>
</div>
</div>
</div>
<?php
} else {
?>
<div class="mspc-variation mspc-horizontal column" data-parameters='<?php
echo $fpd_params;
?>
' data-image='<?php
echo $stage_image[0];
//.........这里部分代码省略.........
示例6: attribute_orderby
/**
* @deprecated 2.1.0
* @param $name
* @return string
*/
public function attribute_orderby($name)
{
_deprecated_function('Woocommerce->attribute_orderby', '2.1', 'wc_attribute_orderby');
return wc_attribute_orderby($name);
}
示例7: widget
/**
* Output widget.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance)
{
global $_chosen_attributes;
if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
$current_term = is_tax() ? get_queried_object()->term_id : '';
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
$taxonomy = isset($instance['attribute']) ? wc_attribute_taxonomy_name($instance['attribute']) : $this->settings['attribute']['std'];
$query_type = isset($instance['query_type']) ? $instance['query_type'] : $this->settings['query_type']['std'];
$display_type = isset($instance['display_type']) ? $instance['display_type'] : $this->settings['display_type']['std'];
if (!taxonomy_exists($taxonomy)) {
return;
}
$get_terms_args = array('hide_empty' => '1');
$orderby = wc_attribute_orderby($taxonomy);
switch ($orderby) {
case 'name':
$get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false;
break;
case 'id':
$get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false;
break;
case 'menu_order':
$get_terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms($taxonomy, $get_terms_args);
if (0 < count($terms)) {
ob_start();
$found = false;
$this->widget_start($args, $instance);
// Force found when option is selected - do not force found on taxonomy attributes
if (!is_tax() && is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) {
$found = true;
}
if ('dropdown' == $display_type) {
// skip when viewing the taxonomy
if ($current_tax && $taxonomy == $current_tax) {
$found = false;
} else {
$taxonomy_filter = str_replace('pa_', '', $taxonomy);
$found = false;
echo '<select class="dropdown_layered_nav_' . $taxonomy_filter . '">';
echo '<option value="">' . sprintf(__('Any %s', 'woocommerce'), wc_attribute_label($taxonomy)) . '</option>';
foreach ($terms as $term) {
// If on a term page, skip that term in widget list
if ($term->term_id == $current_term) {
continue;
}
// Get count based on current view
$_products_in_term = wc_get_term_product_ids($term->term_id, $taxonomy);
$option_is_set = isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']);
// If this is an AND query, only show options with count > 0
if ('and' == $query_type) {
$count = sizeof(array_intersect($_products_in_term, WC()->query->filtered_product_ids));
if (0 < $count) {
$found = true;
}
if (0 == $count && !$option_is_set) {
continue;
}
// If this is an OR query, show all options so search can be expanded
} else {
$count = sizeof(array_intersect($_products_in_term, WC()->query->unfiltered_product_ids));
if (0 < $count) {
$found = true;
}
}
echo '<option value="' . esc_attr($term->term_id) . '" ' . selected(isset($_GET['filter_' . $taxonomy_filter]) ? $_GET['filter_' . $taxonomy_filter] : '', $term->term_id, false) . '>' . esc_html($term->name) . '</option>';
}
echo '</select>';
wc_enqueue_js("\n\t\t\t\t\t\tjQuery( '.dropdown_layered_nav_{$taxonomy_filter}' ).change( function() {\n\t\t\t\t\t\t\tvar term_id = parseInt( jQuery( this ).val(), 10 );\n\t\t\t\t\t\t\tlocation.href = '" . preg_replace('%\\/page\\/[0-9]+%', '', str_replace(array('&', '%2C'), array('&', ','), esc_js(add_query_arg('filtering', '1', remove_query_arg(array('page', 'filter_' . $taxonomy_filter)))))) . "&filter_{$taxonomy_filter}=' + ( isNaN( term_id ) ? '' : term_id );\n\t\t\t\t\t\t});\n\t\t\t\t\t");
}
} else {
// List display
echo '<ul>';
// flip the filtered_products_ids array so that we can use the more efficient array_intersect_key
$filtered_product_ids = array_flip(WC()->query->filtered_product_ids);
foreach ($terms as $term) {
// Get count based on current view - uses transients
$_products_in_term = wc_get_term_product_ids($term->term_id, $taxonomy);
$option_is_set = isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']);
// skip the term for the current archive
if ($current_term == $term->term_id) {
continue;
}
// If this is an AND query, only show options with count > 0
if ('and' == $query_type) {
//.........这里部分代码省略.........
示例8: wc_attribute_orderby
/**
* @since 1.1.0 of SA_WC_Compatibility
*/
public static function wc_attribute_orderby($label)
{
if (self::is_wc_21()) {
return wc_attribute_orderby($label);
} else {
global $woocommerce;
return $woocommerce->attribute_orderby($label);
}
}
示例9: widget
public function widget($args, $instance)
{
global $_chosen_attributes, $woocommerce;
if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
$current_term = is_tax() ? get_queried_object()->term_id : '';
$current_tax = is_tax() ? get_queried_object()->taxonomy : '';
$taxonomy = isset($instance['attribute']) ? wc_attribute_taxonomy_name($instance['attribute']) : $this->settings['attribute']['std'];
$query_type = isset($instance['query_type']) ? $instance['query_type'] : $this->settings['query_type']['std'];
$display_type = isset($instance['display_type']) ? $instance['display_type'] : $this->settings['display_type']['std'];
if (!taxonomy_exists($taxonomy)) {
return;
}
$get_terms_args = array('hide_empty' => '1');
$orderby = wc_attribute_orderby($taxonomy);
switch ($orderby) {
case 'name':
$get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false;
break;
case 'id':
$get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false;
break;
case 'menu_order':
$get_terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms($taxonomy, $get_terms_args);
$width = 32;
$height = 32;
$swatch_type_options = array('color', 'photo');
//$swatch_type_options = maybe_unserialize( get_post_meta( $product_id, '_swatch_type_options', true ) );
// if ( !$swatch_type_options ) {
// $swatch_type_options = array();
// }
if (0 < count($terms)) {
ob_start();
$found = false;
echo $args['before_widget'];
if ($title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base)) {
echo $args['before_title'] . $title . $args['after_title'];
}
// Force found when option is selected - do not force found on taxonomy attributes
if (!is_tax() && is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) {
$found = true;
}
// List display
echo '<ul class="swatches-options clearfix">';
foreach ($terms as $term) {
$type = get_woocommerce_term_meta($term->term_id, $term->taxonomy . '_swatches_id_type', true);
if (!in_array($type, $swatch_type_options)) {
continue;
}
// Get count based on current view - uses transients
$transient_name = 'wc_ln_count_' . md5(sanitize_key($taxonomy) . sanitize_key($term->term_taxonomy_id));
if (false === ($_products_in_term = get_transient($transient_name))) {
$_products_in_term = get_objects_in_term($term->term_id, $taxonomy);
set_transient($transient_name, $_products_in_term);
}
$option_is_set = isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']);
// skip the term for the current archive
if ($current_term == $term->term_id) {
continue;
}
// If this is an AND query, only show options with count > 0
if ('and' == $query_type) {
$count = sizeof(array_intersect($_products_in_term, WC()->query->filtered_product_ids));
if (0 < $count && $current_term !== $term->term_id) {
$found = true;
}
if (0 == $count && !$option_is_set) {
continue;
}
// If this is an OR query, show all options so search can be expanded
} else {
$count = sizeof(array_intersect($_products_in_term, WC()->query->unfiltered_product_ids));
if (0 < $count) {
$found = true;
}
}
$arg = 'filter_' . sanitize_title($instance['attribute']);
$current_filter = isset($_GET[$arg]) ? explode(',', $_GET[$arg]) : array();
if (!is_array($current_filter)) {
$current_filter = array();
}
$current_filter = array_map('esc_attr', $current_filter);
if (!in_array($term->term_id, $current_filter)) {
$current_filter[] = $term->term_id;
}
// Base Link decided by current page
if (defined('SHOP_IS_ON_FRONT')) {
$link = home_url();
} elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
$link = get_post_type_archive_link('product');
} else {
$link = get_term_link(get_query_var('term'), get_query_var('taxonomy'));
}
//.........这里部分代码省略.........
示例10: get_variation_items
private function get_variation_items($attribute_name, $options, $color_config, $productId, $default_value)
{
$orderby = wc_attribute_orderby($attribute_name);
$attribute_type = get_variation_attribute_type($attribute_name);
$base_layer = get_post_meta($productId, "_wpc_base_color_dependency", true);
$edge_layer = get_post_meta($productId, "_wpc_edge_layer", true);
$emb_layer = get_post_meta($productId, "_wpc_emb_layer", true);
$model_layer = get_post_meta($productId, "_wpc_color_dependency", true);
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC', 'hide_empty' => false);
break;
}
$terms = get_terms($attribute_name, $args);
ob_start();
?>
<ul class="attribute_loop">
<?php
if (isset($terms) && !empty($terms)) {
foreach ($terms as $term) {
if (has_term(absint($term->term_id), $attribute_name, $productId)) {
?>
<li class="wpc-variation wpc_term_<?php
echo $term->slug;
?>
"
data-att="<?php
echo $attribute_name;
?>
" data-attvalue="<?php
echo $term->slug;
?>
">
<?php
if ($attribute_type == "image") {
$attr_image = get_option('_wpc_variation_attr_image_' . $term->term_id);
$available_models = get_post_meta($productId, '_wpc_available_models', true);
$extraClass = in_array($term->term_id, $available_models) ? "wpc_available_model" : "";
$selected_class = $term->slug == $default_value ? "atv" : "";
$model_class = $attribute_name == $model_layer ? "wpc_model" : "";
?>
<a href="#" data-display="<?php
echo $term->name;
?>
" class="<?php
echo $model_class;
?>
<?php
echo $selected_class;
?>
<?php
echo $extraClass;
?>
wpc_attribute_button_<?php
echo $attribute_name . '_' . $term->slug;
?>
"
data-attribute="<?php
echo $attribute_name;
?>
" data-id="<?php
echo $term->term_id;
?>
" data-term="<?php
echo $term->slug;
?>
">
<img src="<?php
echo $attr_image;
?>
"
title="<?php
echo $term->name;
?>
"/><span><?php
echo $term->name;
?>
</span>
</a>
<?php
if ($term->slug == $default_value) {
echo '<i class="fa fa-check"></i>';
self::$default_model = $term->term_id;
self::$colorsMeta = get_post_meta($productId, "_wpc_colors_" . self::$default_model, true);
self::$textureMeta = get_post_meta($productId, "_wpc_textures_" . self::$default_model, true);
}
?>
<?php
} else {
$activeClass = $term->slug == $default_value ? "atv" : "";
$button_class = null;
$no_cords = get_post_meta($productId, "_wpc_no_cords", true);
$texture_cords = get_post_meta($productId, "_wpc_multicolor_cords", true);
$static_layer = get_post_meta($productId, "_wpc_static_layers", true);
//.........这里部分代码省略.........
示例11: elseif
$variations_show_name = $variations_options[$att_id]['variations_show_name'];
}
$variations_show_reset_button = "";
if (isset($variations_options[$att_id]) && !empty($variations_options[$att_id]['variations_show_reset_button'])) {
$variations_show_reset_button = $variations_options[$att_id]['variations_show_reset_button'];
}
if (isset($_REQUEST['attribute_' . $att_id])) {
$selected_value = $_REQUEST['attribute_' . $att_id];
} elseif (isset($selected_attributes[$att_id])) {
$selected_value = $selected_attributes[$att_id];
} else {
$selected_value = '';
}
// Get terms if this is a taxonomy - ordered
if (taxonomy_exists($att_id)) {
$orderby = wc_attribute_orderby($att_id);
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC', 'hide_empty' => false);
break;
}
$terms = get_terms($att_id, $args);
$flipped_haystack = array_flip($options);
$_index = 0;
foreach ($terms as $term) {
示例12: get_product_attribute_terms
/**
* Get a listing of product attribute terms.
*
* @since 2.5.0
* @param int $attribute_id Attribute ID.
* @param string|null $fields Fields to limit response to.
* @return array
*/
public function get_product_attribute_terms($attribute_id, $fields = null)
{
try {
// Permissions check.
if (!current_user_can('manage_product_terms')) {
throw new WC_API_Exception('woocommerce_api_user_cannot_read_product_attribute_terms', __('You do not have permission to read product attribute terms', 'woocommerce'), 401);
}
$taxonomy = wc_attribute_taxonomy_name_by_id($attribute_id);
if (!$taxonomy) {
throw new WC_API_Exception('woocommerce_api_invalid_product_attribute_id', __('A product attribute with the provided ID could not be found', 'woocommerce'), 404);
}
$args = array('hide_empty' => false);
$orderby = wc_attribute_orderby($taxonomy);
switch ($orderby) {
case 'name':
$args['orderby'] = 'name';
$args['menu_order'] = false;
break;
case 'id':
$args['orderby'] = 'id';
$args['order'] = 'ASC';
$args['menu_order'] = false;
break;
case 'menu_order':
$args['menu_order'] = 'ASC';
break;
}
$terms = get_terms($taxonomy, $args);
$attribute_terms = array();
foreach ($terms as $term) {
$attribute_terms[] = array('id' => $term->term_id, 'slug' => $term->slug, 'name' => $term->name, 'count' => $term->count);
}
return array('product_attribute_terms' => apply_filters('woocommerce_api_product_attribute_terms_response', $attribute_terms, $terms, $fields, $this));
} catch (WC_API_Exception $e) {
return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
}
}
示例13: __
<option value=""><?php
echo __('Choose an option', 'woocommerce');
?>
…</option>
<?php
if (is_array($options)) {
if (isset($_REQUEST['attribute_' . sanitize_title($name)])) {
$selected_value = $_REQUEST['attribute_' . sanitize_title($name)];
} elseif (isset($selected_attributes[sanitize_title($name)])) {
$selected_value = $selected_attributes[sanitize_title($name)];
} else {
$selected_value = '';
}
// Get terms if this is a taxonomy - ordered
if (taxonomy_exists($name)) {
$orderby = wc_attribute_orderby($name);
switch ($orderby) {
case 'name':
$args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
break;
case 'id':
$args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
break;
case 'menu_order':
$args = array('menu_order' => 'ASC', 'hide_empty' => false);
break;
}
$terms = get_terms($name, $args);
foreach ($terms as $term) {
if (!in_array($term->slug, $options)) {
continue;
示例14: widget
/**
* Output widget.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance)
{
if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$taxonomy = isset($instance['attribute']) ? wc_attribute_taxonomy_name($instance['attribute']) : $this->settings['attribute']['std'];
$query_type = isset($instance['query_type']) ? $instance['query_type'] : $this->settings['query_type']['std'];
$display_type = isset($instance['display_type']) ? $instance['display_type'] : $this->settings['display_type']['std'];
if (!taxonomy_exists($taxonomy)) {
return;
}
$get_terms_args = array('hide_empty' => '1');
$orderby = wc_attribute_orderby($taxonomy);
switch ($orderby) {
case 'name':
$get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false;
break;
case 'id':
$get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false;
break;
case 'menu_order':
$get_terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms($taxonomy, $get_terms_args);
if (0 === sizeof($terms)) {
return;
}
switch ($orderby) {
case 'name_num':
usort($terms, '_wc_get_product_terms_name_num_usort_callback');
break;
case 'parent':
usort($terms, '_wc_get_product_terms_parent_usort_callback');
break;
}
ob_start();
$this->widget_start($args, $instance);
if ('dropdown' === $display_type) {
$found = $this->layered_nav_dropdown($terms, $taxonomy, $query_type);
} else {
$found = $this->layered_nav_list($terms, $taxonomy, $query_type);
}
$this->widget_end($args);
// Force found when option is selected - do not force found on taxonomy attributes
if (!is_tax() && is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) {
$found = true;
}
if (!$found) {
ob_end_clean();
} else {
echo ob_get_clean();
}
}
示例15: widget
/**
* Show widget to user
*
* @param array $args
* @param array $instance
*/
function widget($args, $instance)
{
$br_options = apply_filters('berocket_aapf_listener_br_options', get_option('br_filters_options'));
if (@$br_options['filters_turn_off']) {
return false;
}
global $wp_query, $wp;
wp_register_style('berocket_aapf_widget-style', plugins_url('../css/widget.css', __FILE__));
wp_enqueue_style('berocket_aapf_widget-style');
/* custom scrollbar */
wp_enqueue_script('berocket_aapf_widget-scroll-script', plugins_url('../js/scrollbar/Scrollbar.concat.min.js', __FILE__), array('jquery'));
wp_register_style('berocket_aapf_widget-scroll-style', plugins_url('../css/scrollbar/Scrollbar.min.css', __FILE__));
wp_enqueue_style('berocket_aapf_widget-scroll-style');
/* main scripts */
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script('berocket_aapf_widget-script', plugins_url('../js/widget.min.js', __FILE__), array('jquery'));
wp_enqueue_script('berocket_aapf_widget-hack-script', plugins_url('../js/mobiles.min.js', __FILE__), array('jquery'));
$wp_query_product_cat = '-1';
if (@$wp_query->query['product_cat']) {
$wp_query_product_cat = explode("/", $wp_query->query['product_cat']);
$wp_query_product_cat = $wp_query_product_cat[count($wp_query_product_cat) - 1];
}
if (!$br_options['products_holder_id']) {
$br_options['products_holder_id'] = 'ul.products';
}
$post_temrs = "[]";
if (@$_POST['terms']) {
$post_temrs = @json_encode($_POST['terms']);
}
wp_localize_script('berocket_aapf_widget-script', 'the_ajax_script', array('current_page_url' => preg_replace("~paged?/[0-9]+/?~", "", home_url($wp->request)), 'ajaxurl' => admin_url('admin-ajax.php'), 'product_cat' => $wp_query_product_cat, 'products_holder_id' => $br_options['products_holder_id'], 'control_sorting' => $br_options['control_sorting'], 'seo_friendly_urls' => $br_options['seo_friendly_urls'], 'berocket_aapf_widget_product_filters' => $post_temrs, 'user_func' => @$br_options['user_func']));
extract($args);
extract($instance);
if ($widget_type == 'update_button') {
set_query_var('title', apply_filters('berocket_aapf_widget_title', $title));
br_get_template_part('widget_update_button');
return '';
}
$product_cat = @json_decode($product_cat);
if ($product_cat) {
$hide_widget = true;
$cur_cat = get_term_by('slug', $wp_query_product_cat, 'product_cat');
$cur_cat_ancestors = get_ancestors($cur_cat->term_id, 'product_cat');
$cur_cat_ancestors[] = $cur_cat->term_id;
if ($product_cat) {
if ($cat_propagation) {
foreach ($product_cat as $cat) {
$cat = get_term_by('slug', $cat, 'product_cat');
if (@in_array($cat->term_id, $cur_cat_ancestors)) {
$hide_widget = false;
}
}
} else {
foreach ($product_cat as $cat) {
if ($cat == $wp_query_product_cat) {
$hide_widget = false;
}
}
}
}
if ($hide_widget) {
return true;
}
}
$woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items();
$terms = $sort_terms = $price_range = array();
if ($attribute == 'price') {
$price_range = BeRocket_AAPF_Widget::get_price_range($wp_query_product_cat, $woocommerce_hide_out_of_stock_items);
if (!$price_range or count($price_range) < 2) {
return false;
}
} else {
$sort_array = array();
$wc_order_by = wc_attribute_orderby($attribute);
if (@$br_options['show_all_values']) {
$terms = BeRocket_AAPF_Widget::get_attribute_values($attribute);
} else {
$terms = BeRocket_AAPF_Widget::get_attribute_values($attribute, 'id', true);
}
if (@count($terms) < 2) {
return false;
}
if ($wc_order_by == 'menu_order') {
foreach ($terms as $term) {
$sort_array[] = get_woocommerce_term_meta($term->term_id, 'order_' . $attribute);
}
array_multisort($sort_array, $terms);
} elseif ($wc_order_by == 'name' or $wc_order_by == 'name_num') {
foreach ($terms as $term) {
$sort_array[] = $term->name;
}
$sort_as = SORT_STRING;
if ($wc_order_by == 'name_num') {
$sort_as = SORT_NUMERIC;
//.........这里部分代码省略.........