skip to Main Content

I’m using the Product Vendors plugin for WooCommerce (https://woocommerce.com/products/product-vendors/).

I’m also creating a custom loop for a page builder module, which pulls products by ID.

Using the above, I’m able to pull the WC_Product data using:

$thisProduct = new WC_product($id);

From there, I can get the price/product image etc using

$image = $thisProduct->get_image();
$price = $thisProduct->get_price();

Does anyone know how I would be able to pull the Vendors name? I’ve one a var_dump on the full $thisProduct, and it doesn’t contain the vendor name anywhere within.

Any help would be much appreciated!

Thanks guys.

2

Answers


  1. Chosen as BEST ANSWER

    I figure this out, In order to retrieve the vendor information, we can use the following ($id being the product ID)

    $sold_by = WC_Product_Vendors_Utils::get_sold_by_link( $id );
    

    $sold_by will then contain an array of the vendor info, such as the store name and the link to the vendor store, which we can retrieve such as:

    $vendor_link = esc_url( $sold_by['link'] );
    $vendor_name = $sold_by['name'];
    

    Thanks guys, hopefully this can be of assistance with someone in the future.


  2. If that product is having a vendor mostly it will be saved under ‘post_author’; You can retrieve Vendor by that author id.

    $author         =   get_user_by( 'id', $product->post->post_author );
    

    This variable $author will have all the info like name.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search