1

Hi there so when I am on a product page and I loop through the variations, I want to list their attributes WITH their titles.

I have my code at a point which lists the variations attribute values but cannot get titles to appear. Here is a screenshot of what I have, the 500/238/530 are the attribute VALUES. enter image description here

Here is my current code:

foreach ($variations as $key => $value) {
            ?>
            <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
                <input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
                <input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
                <?php
                if(!empty($value['attributes'])){
                    foreach ($value['attributes'] as $attr_key => $attr_value) {
                    ?>
                    <input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
                    <?php
                    }
                }
                ?>
                <table>
                    <tbody>
                        <tr>
                            <td>
                                <b><?php echo implode('/', $value['attributes']);?></b>
                            </td>
                            <td>
                                <?php echo $value['price_html'];?>
                            </td>
                            <td>
                                <button type="submit" class="single_add_to_cart_button button alt"><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
                                <a href="#" class="add-request-quote-button button" data-product_id="<?php echo $value['variation_id']?>" data-wp_nonce="8b92ff6dd4">Add to quote</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
            <?php
            }

How can I add in each attributes title? I have tried this link which resulted int eh NULLs you can see in my image.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.