Support

Account

Home Forums General Issues Show Custom Fields in Woocommerce Product Compare

Solved

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.

    Thanks

  • See, Can I customize the compare table? on this page https://wordpress.org/plugins/yith-woocommerce-compare/faq/

    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 ?

    Thanks

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

    Thanks

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

    wp-content/themes/my-theme/woocommerce/compare.php

    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 🙁
    http://www.watchoogle.com/novelties/tourbillons/tourbillon-of-tourbillons-steel-gold-18kt-and-titanium-gr5/

    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 ?

    Thanks

  • 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

    
    <?php 
      // 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
             $product->id
            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>';
                      break;
          
                  case 'add-to-cart':
                      $wc_get_template( 'loop/add-to-cart.php' );
                      break;
          
                  default:
                      echo empty( $product->fields[$field] ) ? '&nbsp;' : $product->fields[$field];
                      break;
              }
              ?>
          </td>
        <?php 
      endforeach 
    ?>
    

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

  • Try to use this plugin https://wordpress.org/plugins/acf-yith-woocommerce-compare-support/
    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.