0

I have a single product page in Woocommerce and on the right, I have a box for different sizes. my current HTML code looks like this:

<div class="panel panel-default dimensions">
                          <div class="panel-heading">Available size(s)</div>
                          <ul class="list-group">
                            <li class="list-group-item">size1</li>
                            <li class="list-group-item">size2</li>
                            <li class="list-group-item">size3</li>
                            <li class="list-group-item">size4</li>
                            <li class="list-group-item">size5</li>
                          </ul>
                        </div>

which shows the sizes how i want it but I want to add my custom Woocommerce product attribute in there using the same style, does anyone have any ideas how this is done?

My product attribute is set to:

Product Sizes:

size1
size2
size3

Thanks

1 Answer 1

0

If I understand your question correctly:

<?php
global $product;
$sizes = $product->get_attribute( 'size' ); $sizes = explode(", ",$sizes); ?>
<?php if($sizes[0]!=''){ // if product sizes are defined ?>
   <ul class="list-group">
    <?php foreach($sizes as $size){ ?>
      <li class="list-group-item"><?php echo $size; ?></li>
    <?php } ?>
  </ul>
<?php } ?>
5
  • it seems to break the site, typo maybe somewhere? I changed the ('size') to my version which is ('product_size')
    – Jenova1628
    Commented Sep 13, 2018 at 10:56
  • Corrected, i forgot the semi-colon after $product
    – Pim
    Commented Sep 13, 2018 at 11:02
  • that fixed the issue but it's loading them all in one list-group-item, in the custom attribute i have put them all in but in a different line, could that be an issue?
    – Jenova1628
    Commented Sep 13, 2018 at 11:04
  • I changed the attribute from the product page to the actual attribute page on the products drop down, does this change the way the code is inputted
    – Jenova1628
    Commented Sep 13, 2018 at 11:29
  • Not sure I understand your question correctly.
    – Pim
    Commented Sep 13, 2018 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.