Saturday, April 20, 2024
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 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' ); ?>
          foreach ($product_attr as $attr) {
              foreach ($attr as $attribute) { ?>
                   <th><?php $attrnames = str_replace("pa_", "", $attribute['name']);
                              echo str_replace("-", " ", $attrnames);
                    <td><?php $attrvalue = array( wc_get_product_terms( get_the_ID(), $attribute['name'], array( 'fields' => 'names' ) ) );
                        $attrvalues = implode(",", $attrvalue[0]);
                        echo $attrvalues;
      <?php } } ?>


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

Jassa Jatt,

Thank you

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


Leave a Reply

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