Here正是我想要实现的目标:
如您所见,您可以根据地区(欧盟,英国,美国)选择鞋码。
经过大量研究,我发现 @ Hambos22 there的解决方案正是我想要做的。但无法实现 @ Hambos22 或 @mikejolley 解决方案。 我认为我遗漏了一些知识,在哪里放置这些代码部分,因为我试图将所有内容放在' function.php' 中,但它只显示我 切换器。
我在属性尺寸(英国,美国)中添加了2个自定义字段。
我的属性slug: size
随ACF添加的变量: uk-size , us-size
我的属性默认值: EU
这是一个php代码段
$us_size = get_field('us_size', $term);
$uk_size = get_field('uk_size', $term);
$cm_size = get_field('cm_size', $term);
printf( '<div class="sizeRadio">
<input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
<label for="%3$s">
<span class="label_show" data-region="eu">%5$s</span>
<span data-region="us">%6$s</span>
<span data-region="uk">%7$s</span>
<span data-region="cm">%8$s</span>
</label>
</div>', $input_name, $esc_value, $id, $checked, $filtered_label, $us_size, $uk_size, $cm_size );
}
这是一个JS代码段
$('[data-chooseregion]').on('click', function(e) {
$(this).addClass('active--sizeSelect').siblings().removeClass('active--sizeSelect');
var $active = $('[data-region=' + $(this).data('chooseregion') + ']').addClass('label_show');
$('[data-region]').not($active).removeClass('label_show');
e.preventDefault();
});
以下是切换台的标记
<?php
echo '<a class="sizeSelect active--sizeSelect" data-chooseregion="eu" href="#">EU</a>';
echo '<a class="sizeSelect" data-chooseregion="us" href="#" >US</a>';
echo '<a class="sizeSelect" data-chooseregion="uk" href="#" >UK</a>';
echo '<a class="sizeSelect" data-chooseregion="cm" href="#" >CM</a>';
?>
任何人都可以帮我解决一下吗?
顺便说一下,我也希望将其作为左侧面板中的过滤器应用于my shop page!
如果需要更多信息,请不要犹豫,我会在12小时内回复。
干杯:)
答案 0 :(得分:0)
对于单品页:
我终于把它整理出来而不是创造一个动态的&#34;数据的变化,我选择从我的pa_size下的2个字段创建一个表,如下所示:
if(!empty($terms)){
echo '<button class="accordion">Size Chart <i class="fa-sitemap"></i></button>
<div class="panel">
<table class="sf-table standard_bordered"><tbody><tr><td><strong>EU</strong></td>';
foreach ($terms as $term) {
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
echo '<td>'. $eu_s .'</td>';
}
echo '</tr><tr><td><strong>UK</strong></td>';
foreach ($terms as $term) {
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
echo '<td>'. $uk_s .'</td>';
}
echo '</tr><tr><td><strong>US</strong></td>';
foreach ($terms as $term) {
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
echo '<td>'. $us_s .'</td>';
}
echo '</tr></tbody></table></div>';
}
对于WC Shop页面上的过滤器:
我创建了一个新的&#34;小部件&#34;转到我的过滤器面板并安装了方便的插件 PHP Text Widget ,它扩展了默认的WordPress文本小部件,使其能够执行PHP代码。
然后将以下代码放入其中:
<div class="filter-size">
<input type="button" name="filterEU" value="EU" onclick="sizesEU()" />
<input type="button" name="filterUK" value="UK" onclick="sizesUK()" />
<input type="button" name="filterUS" value="US" onclick="sizesUS()" />
</div>
<?php
global $product;
$terms = get_terms( 'pa_size', $args );
$page_url = esc_url( home_url( '/' ) );?>
<div id="filterEU">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $eu_s ?></a>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<div id="filterUK" style="display:none">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $uk_s ?></a></li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<div id="filterUS" style="display:none">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $us_s ?></a></li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<script>
function sizesEU() {
document.getElementById('filterEU').style.display = "block";
document.getElementById('filterUK').style.display = "none";
document.getElementById('filterUS').style.display = "none";
}
function sizesUK() {
document.getElementById('filterEU').style.display = "none";
document.getElementById('filterUK').style.display = "block";
document.getElementById('filterUS').style.display = "none";
}
function sizesUS() {
document.getElementById('filterEU').style.display = "none";
document.getElementById('filterUK').style.display = "none";
document.getElementById('filterUS').style.display = "block";
}
</script>
如果有任何疑问,请不要犹豫。
干杯