简体   繁体   English

WP-属性和过滤器区域大小调整(欧盟,英国,美国..)

[英]WP - Attribute and filter Region Sizing (EU, UK, US..)

Here is what I'm trying to achieve: 是我要实现的目标:

As you can see here, you can choose shoe size based on the region (EU, UK, US). 如您在此处看到的,您可以根据地区(欧盟,英国,美国)选择鞋码。

After lot of research, I found the solution from @Hambos22 there to be exactly the one I am trying to do. 大量的研究后,我发现从@ Hambos22的解决方案是完全一个我想要做的事。 But impossible to put in place neither @Hambos22 or @mikejolley solution. 但是无法将@ Hambos22@mikejolley解决方案都放置到位。 I think that I am missing some knowledge where to put these parts of code as I am trying to put everything inside 'function.php' but it's only displaying me the switcher. 我想在将所有内容放入“ function.php”中时缺少一些知识,将这些部分放在哪里,但这只是向我显示了切换器。

I've added 2 more custom fields in the Attribute size (UK, US). 我在“属性” 大小 (英国,美国)中添加了2个其他自定义字段。

My website link 我的网站链接

My attribute slug: size 我的属性: 大小

Variables added with ACF: uk-size , us-size 随ACF添加的变量: uk-sizeus-size

My attribute default value: EU 我的属性默认值: 欧盟

Code I would like to put in place (but don't know the location): 我想放置的代码(但不知道位置):

Here is a php snippet 这是一个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 );
}

Here is a JS snippet 这是一个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();
                    });

Here is the markup for the switcher 这是切换台的标记

<?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>';
?>

Anyone could help me to sort it out? 有人可以帮我解决吗?

By the way I would also love to apply that to my shop page as a filter in the left panel! 顺便说一句,我也很乐意将其应用到我的商店页面,作为左侧面板中的过滤器!

If any more information needed don't hesitate I would reply in less than 12 hours. 如果需要更多信息,请在不到12小时内回复。

Cheers :) 干杯:)

For the single product page: 对于单个产品页面:

I finally sort it out and instead of creating a "dynamic" data's change, I chose to create a table from the 2 fields under my pa_size as follow: 我最终进行了排序,而不是创建“动态”数据的更改,而是选择在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>';
}

For the Filter on WC Shop page: 对于“ WC Shop上的过滤器”页面:

I've created a new "widget" going to my filter panel and also installed the handy plugin PHP Text Widget which Extends the default WordPress text widget making it able to execute PHP code. 我创建了一个新的“小部件”,将其转到过滤器面板,还安装了方便的插件PHP Text Widget ,该插件扩展了默认的WordPress文本小部件,使其能够执行PHP代码。

Then put the following code in it: 然后将以下代码放入其中:

<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>

Don't hesitate if any question about it. 如有任何疑问,请不要犹豫。

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM