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
<?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] ) ? ' ' : $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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.