• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

How to show product category names in product page??

Modules
4
7
1.0k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B
    bzay23 last edited by 15 Nov 2021, 06:49

    How to show product category names in product page??

    1 Reply Last reply Reply Quote 0
    • devansh-webkul
      devansh-webkul last edited by 15 Nov 2021, 12:59

      Can you share the screenshot where you want it because category names are already fetching?

      B 1 Reply Last reply 22 Nov 2021, 14:13 Reply Quote 0
      • 7 days later
      • B
        bzay23 @devansh-webkul last edited by 22 Nov 2021, 14:13

        @devansh-webkul i want to show it in product detail page how to fetch it.
        {{$product->category->name}} not working

        1 Reply Last reply Reply Quote 0
        • devansh-webkul
          devansh-webkul last edited by devansh-webkul 23 Nov 2021, 04:26 23 Nov 2021, 04:25

          Its categories,
          https://github.com/bagisto/bagisto/blob/b8e2fd04e6bc597df297b06893168e8b79e630d2/packages/Webkul/Product/src/Models/Product.php#L147

          1 Reply Last reply Reply Quote 0
          • L
            lukas last edited by 25 Nov 2021, 15:16

            @bzay23 said in How to show product category names in product page??:

            {{$product->category->name}}

            {{$product->categories->name}} also not working. Anyone got a solution?

            1 Reply Last reply Reply Quote 0
            • devansh-webkul
              devansh-webkul last edited by 26 Nov 2021, 04:56

              You can't directly call name on the categories. Just die and dump $product->categories, you will get to know.

              1 Reply Last reply Reply Quote 1
              • K
                kellertxroofing last edited by 26 Nov 2021, 11:48

                @bzay23 said in How to show product category names in product page??:

                How to show product category names in product page

                function my_add_woo_cat_class($classes) {

                $wooCatIdForThisProduct = "?????"; //help!
                
                // add 'class-name' to the $classes array
                $classes[] = 'my-woo-cat-id-' . $wooCatIdForThisProduct;
                // return the $classes array
                return $classes;
                

                }

                //If we're showing a WC product page
                if (is_product()) {
                // Add specific CSS class by filter
                add_filter('body_class','my_add_woo_cat_class');
                }
                source: stackoverflow

                1 Reply Last reply Reply Quote -1
                2 out of 7
                • First post
                  2/7
                  Last post