Recent Topics

get category of product

  • hello
    i need to view the root gategory for each product when view info of product
    how i can get the category of product by product

  • Hi @Ahed ,
    You can call the following method to get the products category-wise.
    You can find the file on the following path:


  • no i need get the category of product

  • Also if you want to find the categories related to the product you can check the following method at the following path:

     * Returns product categories
     * @param \Webkul\Product\Contracts\Product|\Webkul\Product\Contracts\ProductFlat  $product
         * @return string
        public function getProductCategories($product)
            if ($product instanceof \Webkul\Product\Models\ProductFlat) {
                $categories = $product->product->categories;
            } else {
                $categories = $product->categories;
            $names = [];
            foreach ($categories as $key => $category) {
                $names[] = $category->name;
            return implode(', ', $names);

  • @Ahed ,
    will you please elaborate on exactly what you want?

Log in to reply