Support » Plugin: WC Marketplace » Product Loop by Vendor

  • Resolved felipemonteiro44


    When I loop to get the products as in the code below it returns me all the products registered. How do I get only the products of the seller that is logged in and show the name and image

    $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1);
    $loop = new WP_Query($args);
    while ( $loop->have_posts() ) : $loop->the_post();

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WC Marketplace


    @felipemonteiro44, please follow this code snippet:

    $vendor = get_wcmp_vendor(get_current_vendor_id());
     if ($vendor->get_products()){
                           foreach ($vendor->get_products() as $product) {
                               $product = wc_get_product($product->ID);
                               echo esc_html($product->get_title());
                       } ?>

    What about the product thumbnail? I tried with get_the_post_thumbnail but it does not return anything.

    Plugin Contributor Purnendu Dash



    You may use this

    to get the product image.

    Perfect thank you. Just one more doubt.
    I have a function of another plugin and the documentation has been saying that it works only if it is inside a loop. With the first code it worked because it was. This one that passed me is not. Is it because you’re using the foreach?

    Plugin Contributor Purnendu Dash



    we are using the foreach and inside the foreach, we created the product object.

    $product = wc_get_product($product->ID);

    Now from that you can able to get all product releated information.

    For further details you may check this –

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Product Loop by Vendor’ is closed to new replies.