How can I get product price, image and perm link by category id woocommerce

krishk varma

I want to fetch all product title, price,img, permlink by category id. I tried to fetch by category name and I got the product in array but there was no image, price data init.

Dao

I think it's what you need. It's the custom WP_Query to get all product data by category id.

$category_id = 10; // replace your category id here
$args = array(
    'post_type'        => 'product',
    'posts_per_page'   => 9, // update your posts_per_page value here
    'post_status'      => 'publish',
    'suppress_filters' => false,
    'tax_query'        => array(
        array(
            'taxonomy' => 'product_cat',
            'terms'    => $category_id,
        ),
    ),
    'fields'           => 'ids'
);

$products_query = new WP_Query($args);
if($products_query->have_posts()){
    foreach($products_query->posts as $product_id){
        $product = wc_get_product($product_id);
        $product_title = get_the_title($product_id);
        $product_image = get_the_post_thumbnail($product_id);
        $product_price = $product->get_price();
        $product_link = get_the_permalink($product_id);
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PHP: Get image to link to Product id (woocommerce)

woocommerce get product category id

How can I get the product price from WooCommerce so i can use it with javascript?

How can I get Min and Max price of a woocommerce variable product in Custom loop?

How can I add below of Woocommerce out of stock product text the Woocommerce product price on a single product

How can i display price in woocommerce product table with custom query?

How can I set tab (only) if the product is in a certain category WooCommerce

Get "primary" category image from WooCommerce product

Get Woocommerce product category image url

Get and display the product category featured image in Woocommerce

Excel: How can I get price from sheet B where product_id is identical product_id in sheet A

Query by product category, product tags and price in Woocommerce

WooCommerce database query : Get product category image path+name from thumbnail_id

woocommerce - How do I get the most top level category of the current product category

Display image below product price based on product category on WooCommerce shop and archive pages

Woocommerce with wordpress - how can I display category image?

How can I get the most used category in a product in MongoDB collection

How to get product price from variable product in WooCommerce?

Total price value per product category - Woocommerce

Hide Price based on product category in Woocommerce

How can I display the image to the desired product category? (if there are two separate models (Product and Image))

Get lowest price bigger than 0 of a simple "instock" product for a specific product category in Woocommerce

How can I get the Price, Title, and the Link from this element tag?

Get the category name from a WooCommerce product using the product id or the category id

Get the product price in Woocommerce 3

Get the product with highest price in Woocommerce

Woocommerce: How do I get the product slug from the id?

Get also WooCommerce product category thumbnail Id using a SQL query

WooCommerce product price visibility: add price back only for a specific category