Support

Account

Home Forums Front-end Issues Having issues with YITH Ajax Product Filter shortcodes?

Solving

Having issues with YITH Ajax Product Filter shortcodes?

  • Hi all, using the latest ACF Pro.

    Following various instructions on these forums to get shortcodes working in text fields, I can get pretty much any shortcode working with no problems. However, specifically I can’t get YITH Ajax Product Filter shortcodes working in ACF fields. Hardcoding these shortcodes in works fine.

    They are typically laid out as so:

    [yith_wcan_filters slug="draft-preset"]

    This turns out blank – ACF doesn’t see the field as filled, and the var_dump says NULL.

    Other shortcodes with variables, like from Contact Form 7, work fine.

    Just wondering if anyone else has faced similar issues? Is there any encoding issues I should be aware of? I have asked YITH but they didn’t have much to say.

    My code:
    Sidebar template:

    <?php if( is_product_category() ) { ?>
    	<?php if ( get_field('filter_shortcode') ) { ?>
    	    <div class="product-filter-widget">
                <?php the_field('filter_shortcode'); ?>
            </div>
        <?php } ?>
    <?php } ?>

    Functions.php

    function text_area_shortcode($value, $post_id, $field) {
      if (is_admin()) {
        // don't do this in the admin
        // could have unintended side effects
        return;
      }
    
      return do_shortcode($value);
    }
    add_filter('acf/load_value/name=filter_shortcode', 'text_area_shortcode', 10, 3);

    Thanks for your time

  • Without trying to figure out the YITH issue, I would first recommend using acf/format_value, not acf/load_value and using a priority of > 10 to ensure it runs after ACF’s built in filter.

    acf/load_value happens before acf/format_value so ACF is trying to format anything you alter the value to during acf/load_value

  • @hube2 thanks as always for your efforts. I’ve changed that, thank you.

    The more I think about this, I wonder if this is AJAX-related. If I try loading a products category with no products in, I can get the value of the field to print. If I try with a category that has products in it, it won’t return anything. This makes me think if my ACF field is trying to load a YITH filter first before the YITH plugin does what it needs to do with checks using AJAX, therefore the filter doesn’t ‘exist’ at that point.

    Would you know of anything I can do with ACF that can ‘listen’ for some AJAX to finish?

  • To be honest, I don’t know. I worked on one site that used the YITH product filter and I never found a way to incorporate ACF fields. We had to build a complex product attribute system in order to get it to work.

    But you are looking to add the product filter shortcode, there really shouldn’t be anything that prevents the shortcode from working. If it were me I would start following the code to see why it’s not.

    Example, is your filter being called? Echo something inside the filter function to see if you get output.

    Is the shortcode function being called? Open the YITH file with the shortcode function and add code to return values and different points to see what is happening inside the shortcode. For example, at the very beginning of the function you could add something like return 'the shortcode is running'; which would be output as content where the shortcode is placed.

  • Thanks for sharing your insight. I did try echoing and it doesn’t return anything. As mentioned it returns NULL when I do a var dump.

    I’ll try what you’ve said in the last paragraph, but to be honest the more time I spend on this, the more I’m thinking I’ll do this the other way around. Create all the filters now, and just use some conditional code in the template to call the correct filter on the correct category page. Not my ideal choice, but there’s only so many hours you can throw at something!

    Cheers John.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.