0

I am trying to get product data from Woocommerce on my Wordpress website. I used the code below to get the name and thumbnail images of products of a particular category.

<?php  
    $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'Tools' );

    $loop = new WP_Query( $args );


    while ( $loop->have_posts() ) : $loop->the_post(); 
    global $product; 

 echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().' '.the_title().'</a>';
    endwhile; 


    wp_reset_query(); 

?>

This works fine in getting the Name and Image of products in the category "Tools", but I want to get the weight for each product.

The product Weight is set as a product attribute in the Wordpress Dashboard.

How do I get this data for products? I can't seem to find the functions to access these.

Tester
  • 2,887
  • 10
  • 30
  • 60

1 Answers1

0

The data you're looking for is stored as an attribute, so there is no function to explicitly pull it like there is for the permalink or the image.

This thread should help point you in the right direction: Woocommerce getting custom attributes

Community
  • 1
  • 1
Dave Mroz
  • 1,509
  • 2
  • 14
  • 27