Home Forums General Issues Show Custom Fields in Woocommerce Product Compare Reply To: Show Custom Fields in Woocommerce Product Compare

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