W
W
woebegone2021-05-02 16:42:59
WordPress
woebegone, 2021-05-02 16:42:59

How to display optional attribute value in wordpress woocomerce?

<?php
global $product;
$attributes = $product->get_attributes();
foreach ( $attributes as $attribute ){
     $name = wc_attribute_label( $attribute['name'] );
     if ($name != 'Region' && $name != 'Fraction' && $name != 'BoostRating' && $name != 'BoostType1') {
        echo "<div class='attributerow radio_wrap'><div class='attributerowname _hidden'>" .  $name . "</div>";
        if ( $attribute['is_taxonomy'] ) {
            $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
            echo apply_filters( 'woocommerce_attribute', wptexturize( implode( ', ', $values ) ), $attribute, $values );
        } else {
          $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
          echo apply_filters( 'woocommerce_attribute', wptexturize( '<div class="radio_line"><p class="radio_block radio"><a href="javascript:void(0)"></a><input type="radio" name="radio"><span class="atname">
                '.implode( '</p></div><div class="radio_line"><p class="radio_block radio"><a href="javascript:void(0)"></a><input type="radio" name="radio"><span class="atprice">11</span><span class="atname">', $values ) . '</span></p></div></div>' ), $attribute, $values );
        }
     }
}
?>


This code displays the name "name" of the product attributes.
But each product has its own price tag, how to display it?
Thank you!
608eac6020f69810766996.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question