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.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.