• Resolved Mike

    (@suchaqd)


    Hey Janw – Thanks for creating this awesome, free plugin! I’m currently using it to display default images for my WooCommerce products; I have a featured image per product tag and everything works beautifully. The only setback I’m having right now is displaying my default product images when using the FacetWP plugin, which seems to ignore the DFI images. I’m using the basic code below for testing purposes, which only displays the actual, uploaded featured image instead of the one that I’ve set using DFI. Not sure what I’m missing but any help is much appreciated!

    FacetWP code:

    <ul class="products">
    <?php while ( have_posts() ) : the_post(); ?>
    <li><?php the_post_thumbnail(); ?></li>
    <?php endwhile; ?>
    </ul>

    DFI code for one of my WC tags (I have several of these):

    function dfi_tag_gameon ( $dfi_id, $post_id ) {
      if ( has_term( 'game-on', 'product_tag', $product ) ){
        return 1155; // the image id
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_tag_gameon', 10 , 2 );

    https://www.ads-software.com/plugins/default-featured-image/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Michael,

    in your code you add a $product to the filter. But it is never given you probably need to add the $post_id in that place to make it work.

    Thread Starter Mike

    (@suchaqd)

    Thanks for the quick reply! I changed $product to $post_id on all of my functions/filters, but the DFI still doesn’t want to display. It works everywhere else on my site except on the FacetWP search results page. I can give you access to my site, if that’ll help explain things more, but I don’t want to spend too much of your time either.

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Michael,

    I rather not go on other people’s servers/websites. My best guess is that
    FacetWP is overriding the DFI. So it probably isn’t using the build in functions like the_post_thumbnail, get_the_post_thumbnail, has_post_thumbnail and get_post_thumbnail_id

    You could check the templates to see what they use. But still they might use some high level filters to override the DFI.

    I’m afraid I can’t help much.

    Thread Starter Mike

    (@suchaqd)

    Thanks again for the quick reply =) So the regular post thumbnail template tag (code below) does work but only for posts where I’ve manually uploaded and set the featured image. It doesn’t work for any of the posts that uses the WooCommerce/tag-based DFI images. I’ll see if the FacetWP dev knows any more about this and maybe I can get this squared away.

    post thumbnail code I’m using:
    <?php the_post_thumbnail(); ?>

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Maybe they use something that looks like a Featured image but isn’t? The Ui can be copied and applied to something else.

    Thread Starter Mike

    (@suchaqd)

    Matt, the FacetWP plugin author, was able to figure it out =) He’s returning the search results on my page via ajax, which gets ignored by the DFI filter, so he changed line 62 in set-default-featured-image.php from

    if ( is_admin() || '_thumbnail_id' != $meta_key )

    to

    if ( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) || '_thumbnail_id' != $meta_key )

    All is well now. Perhaps, you can update your plugin, if other people run into the same issue =) Thanks again for all your help, Matt and Janw!

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi Michael,

    That’s one hell of an if statement. I’m not sure I understand it.
    So with this code you do get the DFI on you searchpage? And on that page the (featured)images are loaded by ajax?

    Because the if suggests that ajax right now will be ignored.

    If that is correct I’ll try to implement it around the holydays.

    Thread Starter Mike

    (@suchaqd)

    Totally. Matt actually referenced this post — https://www.ads-software.com/support/topic/consider-checking-doing_ajax-for-is_admin-checks?replies=3 — in an email to me, which I thought was pretty interesting. In any case, the updated code will display DFIs on the ajaxed search page =)

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi Michael,

    I tested the fix and implemented it in version 1.4
    So it’s save to update.

    Thread Starter Mike

    (@suchaqd)

    Thanks so much for the update! Everything works =)

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘DFI WooCommerce FacetWP’ is closed to new replies.