Support » Plugin: WP eCommerce » Integration with ACF Relationship Field

  • I’m trying to get data from a product within a relationship field through “Advanced Custom Fields”. I am able to get the product title and page link no problem, but am having a hard time with getting the product price, thumbnail and additional description. Here is my code:

    <!----------------------- similar wrap by choice ------------------------------>
    <?php $value1 = get_field('similar_products'); ?>
    <?php if ($value1){ ?>
    <?php foreach(get_field('similar_products') as $similarproduct):?>
          <!--featured image-->
      <?php if ( wpsc_the_product_thumbnail($similarproduct->ID) ) : ?>
               <img class="product_image" width="75" height="131" alt="<?php echo wpsc_the_product_title($similarproduct->ID); ?>" title="<?php echo wpsc_the_product_title($similarproduct->ID); ?>" src="<?php echo wpsc_the_thumbnail($similarproduct->ID); ?>"/>
                          <?php endif; ?><!-----------end product image ------------>
    		      <h1><a href="<?php echo get_permalink($similarproduct->ID); ?>" title="<?php echo the_title_attribute($similarproduct->ID); ?>"><?php echo get_the_title($similarproduct->ID); ?></a></h1>
          		   <p><?php echo wpsc_the_product_price($similarproduct->ID); ?></p>
                   <p><?php echo wpsc_the_product_additional_description($similarproduct->ID); ?></p>
                   <div class="view"><a href="<?php echo get_permalink($similarproduct->ID);?>"></a></div>
     <?php endforeach; ?>
    <?php } ?>

    The results is that the titles are correct, but the images, price and descriptions are displaying the current product, not the products within the relationship field. I’m guessing it has something to do with:

    not working within “foreach” or accepting the parameters of the relationship field?

Viewing 1 replies (of 1 total)
  • OK, I got the image and price to work by changing it to:

    <?php if (has_post_thumbnail($similarproduct->ID) ) : ?>
          <?php echo get_the_post_thumbnail($similarproduct->ID, 'category-product'); ?>
            <?php endif; ?>
    <p><?php echo get_post_meta( $similarproduct->ID, '_wpsc_special_price', true );?></p>

    still trying to figure out the additional description

Viewing 1 replies (of 1 total)
  • The topic ‘Integration with ACF Relationship Field’ is closed to new replies.