Need code to display product variation title in the cart summary

edited April 2013 in Shopping Cart plugin
Hi,

I'm looking for the code fragment to display the product variation details in the cart summary. 

By default the product details get displayed but there is no mention of any product variations.

Anyone got any ideas on how to do this?

cheers,

James B. 

Comments

  • 4 Comments sorted by
  • Vote Up0Vote Down
    Thank you for your post, James.

    The cart summary file doesn't display the variations and custom fields because it is intended to be just a summary and not a full display of the shopping cart. You can modify it though.

    These details are displayed in the shopping cart page though, so you can copy code from the shopping cart page to the cart summary. The shopping cart page template file is wp-checkout/views/default/cart.php and there are 2 blocks of code you can copy. The styles and the cfields. That is the variations and the custom fields.

    Then paste it into the foreach items loop of the cart summary. The cart summary file is wp-checkout/views/default/cart-summary.php

    Let me know if this helps please.

    All the best,
    Antonie
  • Vote Up0Vote Down
    Hi Antonie,

    I am also looking for this feature. Can you paste the exact code needed to get this to work?

    Thanks in advance,

    Pádraig
  • Vote Up0Vote Down
    edited July 2013
    Thanks to Antonie for helping with this via my support ticket. Posting here so it may be of use to others.
    The code Antonie referred me to was not in wp-checkout/views/default/cart.php in the default theme. However it was in wp-checkout/views/default/cart.php in the simplyblue theme.

    AFTER the following code in cart-summary.php [line 46 approx.]
    <td class="wpco_columntitle">
    <?php echo apply_filters($this -> pre . '_product_title', $item -> product -> title); ?>

    paste the code [highlighted in yellow] below.  Thanks again to Antoine.

    <pre lang="php">
    <?php if ($styles = maybe_unserialize($item -> styles)) : ?>
    <?php foreach ($styles as $style_id => $option_id) : ?>
    <?php $wpcoDb -> model = $Style -> model; ?>
    <?php if ($style = $wpcoDb -> find(array('id' => $style_id), array('id', 'title'))) : ?>
    <?php if (!empty($option_id) && is_array($option_id)) : ?>
    <?php $option_ids = $option_id; ?>

    <?php $o = 1; ?>
    <?php foreach ($option_ids as $option_id) : ?>
    <?php $wpcoDb -> model = $Option -> model; ?>
    <?php if ($option = $wpcoDb -> find($conditions = array('id' => $option_id), $fields = array('id', 'title', 'addprice', 'price', 'operator'), $order = array('id', "DESC"), $assign = true)) : ?>
    <?php echo $option -> title; ?><?php echo (!empty($option -> addprice) && $option -> addprice == "Y") ? ' (' . __('+', $this -> plugin_name) . $wpcoHtml -> currency_price($option -> price, true, false, $option -> operator) . ')' : ''; ?>
    <?php echo ($o < count($option_ids)) ? ', ' : ''; ?>
    <?php endif; ?>
    <?php $o++; ?>
    <?php endforeach; ?>


    <?php else : ?>
    <?php $wpcoDb -> model = $Option -> model; ?>
    <?php $option = $wpcoDb -> find($conditions = array('id' => $option_id), false, array('id', "DESC"), true, array('otheroptions' => $styles)); ?>
    <tr>
    <th><?php echo $style -> title; ?></th>
    <td><?php echo $option -> title; ?><?php echo (!empty($option -> addprice) && $option -> addprice == "Y" && !empty($option -> price)) ? ' (' . __('+', $this -> plugin_name) . $wpcoHtml -> currency_price($option -> price, true, false, $option -> operator) . ')' : ''; ?></td>
    </tr>
    <?php endif; ?>
    <?php endif; ?>
    <?php endforeach; ?>
    <?php endif; ?>
    <?php if (!empty($item -> product -> cfields)) : ?>
    <?php foreach ($item -> product -> cfields as $field_id) : ?>
    <?php $wpcoDb -> model = $wpcoField -> model; ?>
    <?php if ($field = $wpcoDb -> find(array('id' => $field_id))) : ?>
    <?php if (!empty($item -> {$field -> slug})) : ?>
    <tr>
    <th><?php echo $field -> title; ?><?php echo (!empty($field -> addprice) && $field -> addprice == "Y" && !empty($field -> price)) ? ' (' . __('+', $this -> plugin_name) . $wpcoHtml -> currency_price($field -> price) . ')' : ''; ?></th>
    <td><?php echo $wpcoField -> get_value($field_id, $item -> {$field -> slug}); ?></td>
    </tr>
    <?php endif; ?>
    <?php endif; ?>
    <?php endforeach; ?>
    <?php endif; ?>
    </pre>
  • Vote Up0Vote Down
    Hello Gortskehy,

    Again, thank you for sharing your code with us.

    All the best!
This discussion has been closed.