Home Forums General Issues Show Custom Fields in Woocommerce Product Compare


Show Custom Fields in Woocommerce Product Compare

  • Hi,
    I want to use custom fields in “yith-woocommerce-compare” plugin.but i don’t know how to show product custom fields on this product compare window.
    Will be so thankful for your kind reply and help.


  • See, Can I customize the compare table? on this page

    Once you have copied the template to your theme you can modify that template to add the additional fields you want to display by following the documentation for ACF.

  • HI John,
    Thanks for reply and your help.
    SO we can get the value of custom fields same like we get in other pages ?


  • Hello John,
    I tried to copy the template folder from plugin and past it inside the theme folder woocommerce.
    But still nothing showing.
    Is there anything else i have to do ?


  • I’m not that familiar with WooCommerce, but I think that the you need to put the template into a folder named woocommerce in you theme folder, and not in a subfolder.


    Then try to make some changes to it, output some text just to make sure it’s working. If not you’ll need to contact the plugin developer.

  • John you are my hero.its working now.
    Now m stuck in showing Custom Fields on this comparison table 🙁

    I tried using shortcode. its working perfect for this product. but its manual.
    <?php //echo do_shortcode(‘[acf field="product_attr_movement" post_id="6121"]‘); ?>

    is there any idea to show all the custom fields for each product ?


  • Can u please check compare.php file ?

  • I’ve looked at that template, to be honest, it would probably take me several hours of trial and error to figure out how to add fields to that template.

    I think it would be done in the foreach loop that starts at line 116, but that’s just a guess.

    I would probably start by trying to add some html and text into different places just to see what happens. Once I figured out how to modify the HTML to output my fields then I’d figure out how to get the acf fields.

    Honestly, the first thing I’d really do is clean up the coding so that it’s easier for me to read and work with, but that’s a different story.

  • Thanks again John.
    I appreciate your help and support.
    I have edited the file and i am able to show the custom fields of product in compare table.But when i compare 3 products its showing only custom fields of latest product. i am not able now to show it in a loop.
    I want to show same like how this Compare plugin show all the fields in a loop.
    Need your help John.
    Will be so thankful to you.

  • Sorry, this got buried in my inbox. The problem I have is that without setting up a woocommerce site to test on and that plugin and everything that goes with it to test and then doing the testing. I’m really not familiar enough with that plugin.

    I think that the place you want to modify is this section of code

      // whitespace altered for clarity
      foreach ($products as $i => $product) : 
        $product_class = ( $i % 2 == 0 ? 'odd' : 'even' ) . ' product_' . $product->id; 
            I think the post ID of the curretn product should be
            but I can't be sure
            you would need to alter this code to add your fields
            but I don't know if you'd add a new <td> for each field or
            add the fields to this <td>
            you would show a field with something like the below
            if $product->id is the post ID
            the_field('my-field-name', $product->id)
          <td class="<?php echo $product_class; ?>"><?php 
              switch( $field ) {
                  case 'image':
                      echo '<div class="image-wrap">' . wp_get_attachment_image( $product->fields[$field], 'yith-woocompare-image' ) . '</div>';
                  case 'add-to-cart':
                      $wc_get_template( 'loop/add-to-cart.php' );
                      echo empty( $product->fields[$field] ) ? '&nbsp;' : $product->fields[$field];

    I hope that helps, but I think it’s the best I’m going to be able to do.

  • Try to use this plugin
    Sorry, I know that it is a little bit late reply, but maybe it will be useful for somebody else.

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

The topic ‘Show Custom Fields in Woocommerce Product Compare’ is closed to new replies.