Categories

Monday, December 23, 2024
#919814419350 therichposts@gmail.com
WoocommerceWordpressWordpress Tricks

How to get Woocommerce Product Attributes names and value?

How to add download pdf link in woocommerce single product page?

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to get woocommerce product attributes names and value?

Woocommerce is know for the best e-commerce wordpress plugin and User can easily add and sell his/her products easily.

Woocommerce has great ability to add extra features or I can extra attributes of any product and I will show the code to get that attributes.



If you are new in Woocommerce then you can check my old posts related to Woocommerce.


1. Here is the code for How to get Woocommerce Product Attributes names and value? and you can add this code anywhere into your wordpress theme’s template file and I am doing to this for single product but we can also use this code in wp query for product:

<?php $product_attr = get_post_meta( get_the_ID(), '_product_attributes' ); ?>
<table>
 <tbody>
      <?php 
          foreach ($product_attr as $attr) {
              foreach ($attr as $attribute) { ?>
                <tr>
                   <th><?php $attrnames = str_replace("pa_", "", $attribute['name']);
                              echo str_replace("-", " ", $attrnames);
                     ?></th>
                    <td><?php $attrvalue = array( wc_get_product_terms( get_the_ID(), $attribute['name'], array( 'fields' => 'names' ) ) );
                        $attrvalues = implode(",", $attrvalue[0]);
                        echo $attrvalues;
                     ?></td>
                </tr>
      <?php } } ?>
 </tbody>
</table>

 

If you have any query related to this post, then please let me know.

Jassa Jatt,

Thank you

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.