Bagisto Forum

    Bagisto

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

    How to show product category names in product page??

    Modules
    4
    7
    1006
    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

      How to show product category names in product page??

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

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

        B 1 Reply Last reply Reply Quote 0
        • B
          bzay23 @devansh-webkul last edited by

          @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

            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

              @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

                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

                  @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
                  • First post
                    Last post