Add the Vendor’s Product Categories to Vendors List Page

This snippet was provided by support to show a list of the product categories each individual vendor has for sale onto the Vendors List page.

Note: I do not use this snippet on my own site, so I don’t know if or how it works. Please let me know in the comments!

As always, this is either added to your Child Theme’s functions.php file, or consider using the My Custom Functions Pro plugin to manage and organize all your snippets.

add_action('wcmp_vendor_lists_vendor_after_store_details', 'show_vendor_categories');

function show_vendor_categories($vendor) {
	$vendor_products = $vendor->get_products(array('fields' => 'ids'));
	$product_categories = array();
	$i = 0;
	echo '<li><b>Categories</b><br>';
	foreach ($vendor_products as $product_id) {
		$product_category_list = wc_get_product_category_list($product_id, $sep='This is a separator');	//lists all categories the product is assigned to
		$product_category_array = explode ('This is a separator', $product_category_list);	//converts the list into an array splitting at the identifier 'This is a separator'
		$product_category = $product_category_array[count($product_category_array)-1];		//Only lowest category hierarchy level to be displayed if product is assigned to category + subcategory					
		if (!in_array($product_category, $product_categories)) {	//makes sure to add only categories that are not yet inside the array
			array_push($product_categories, $product_category);
			if ($i == 0) {
				echo $product_category;
			} else {
				echo ', '.$product_category;	//adds a comma if more than one category will be shown
	echo '</li>';

Tested and working on Woocommerce 4.6.1, WCMp 3.5.10

Is this no longer relevant or not working? Please let us know in the comments!

One thought on “Add the Vendor’s Product Categories to Vendors List Page

  1. Thank you so much for sharing your code! I have tried 3 snippets and work with charm like I’ve never seen with WCmp support.
    Please contact me, we would like to hire you to help us with some WCmp concerns.

Comments on this post

Your email address will not be published. Required fields are marked *