The get_category_parents is a function that retrieve the parent categories passing as argument a category id.
So, if you have a product and you want to retrieve a list of attached categories to it, the right function is get_the_terms.That function return all the categories objects, without order, and so you can take the first of these categories and call get_category_parents.
Assuming the $product variable contain a post object, you can use
$cats = get_the_terms( $product->ID, 'product_cat' );
echo $cats ? get_category_parents( array_shift($cats)->term_id ) : '';
Related Posts:
- How to make plugin required in a wp theme without using php conditional statements when calling an individual function from that plugin?
- Replacing Icons in the Dashboard
- Where are plugins located
- Checking if an attribute exists in a shortcode
- Delete Post With No Traffic?
- A Way to Auto update plugins using cron?
- WP plugin management
- What’s the recommended process for organising collaborative posting?
- Is there a plugin that pushes posts to your Google+ profile?
- Leverage browser caching not working after updating .htaccess
- How to attach Links into page/post or custom post type?
- How can I filter blog name?
- How can I make the “Preview Post” button save and preview in the same window?
- WordPress Custom Application form
- Cannot run the code after I activate the plugin
- Plugin could not be activated because it triggered a fatal error. (No Error??)
- Adding a jquery script to plugin contact form 7
- How to retrieve custom meta term of category taxonomy from WP Rest API?
- Problem with wp_enqueue_scripts in plugin
- Best Practice: Remove data on deactivation or uninstall?
- WooCommerce & Caching [closed]
- Show Heirachy of categories in WP Download Monitor
- How to replace or display the special characters from JSON API plugin [closed]
- add_query_arg not working
- myCRED custom hook preferences doesn’t update creds and log
- Limit Number of Taxonomy Terms (Images) Displayed
- Widget for adding HTML markup to a page
- importing plugin w/ settings from one WP installation to another
- After plugin options changed hook
- How to make a slideshow shortcode based on the WordPress gallery shortcode? [closed]
- How to enable qTranslate languages tabs in custom plugin page
- Linking an image to open a youtube video in lightbox/fancybox in wordpress
- Making a Template for a CPT created by a plugin
- Woocommerce dependent plugin
- Get sent emails without email logs
- External CSS in WordPress Plugin [closed]
- PHP basics help in WP context – remove a class/function?
- User registration
- Plugin dependencies: show notice like theme plugins dependencies
- get 404 when accessing wp-admin/plugin-install.php
- What will happen if i deactivate my visual composer plug in? [closed]
- Custom Pages for Woocommerce Product-Category Pages
- Woocommerce Minimum Price for a Composite Product to add in cart
- What is most efficient way to migrate wordpress website?
- Bulk updates to post_content
- Migrating problem from Joomla to WP
- User Signup in Multisite – Need Plugin or Advice
- Plugin – Social media share buttons
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Translation plugin to translate another plugins
- How can I list all installed plugins/themes/versions from CLI/API?
- Notice: Uninitialized string offset: 0 in social sharing mu-plugin
- How to deploy gutenberg on my own [closed]
- Shortcode to update user meta
- Adding Static Image to WooCommerce Content-Single-Product template
- How to protect WordPress from security scanner [closed]
- how can I query all wordpress users of a blog
- Automate paragraphs in a post page to have a unique anchor link
- After updating the WordPress getting a syntax error in the console
- How to redirect to same page after form submission
- How to add a new column with text fields to WooCommerce Cart List?
- How to use filter to disable adding a product to wishlist?
- Merge tags in multistep Gravity Form?
- Call a function for social sharing
- Add a file upload field
- Is there anyway to rewrite woocommerce-template.php?
- Apply html elements in php statement
- How to find the WordPress Nextgen galleries which are not used in WordPress posts?
- Get product categories and add them to a custom taxonomy
- I want to add the below chatbot html code to index(main) file of WordPress sites how can I do that
- add_rewrite_rule to load different page, without changing URL in browser
- Gzip compression or Mod_deflate not working
- How to find the file path in WordPress?
- Shortcode show error while editing post
- Which membership plugin for a simple sign in? Personal areas for customers
- What are the disadvantages of using template_redirect for restrictions
- Circular Menu to show on pages
- Swap themes locally
- Different function call depending on shortcode?
- How to add add blank non-editable wp page like default blog for use with plugin
- How To Add Code To WP Without Plugin or Functions
- Run one-time script calling plugin functions
- Adding icons next to categories in wp_nav_menu
- Custom plugin breaks css.php on Multisite
- admin panel save option with ajax
- Woocommerce Subscriptions – Customer change subscribed product after placed
- How to Change MU/BuddyPress Group Blog New Installation Defaults [closed]
- Retrieving old forms in Contact Form 7 [closed]
- Advice on setting up private site
- is ther a plugin that will hide/show content for a scheduled period of time? [closed]
- update_post_meta not working
- Pulling Advanced Custom Fields from other pages
- Trying to use Advanced Custom Fields with custom image sizes
- Loading post that has visual composer data inside lightbox? [closed]
- Manage Inventory Without Displaying Levels
- registration plugin [closed]
- Which action/filter can i use for a Member Plugin [closed]
- WordPress Share Buttons Plugin: How do you make the WordPress Share Buttons Display Vertically?
- Plugin translations are not loaded from translate.wordpress.org
- Add new Plugin or Delete option Not Showing and Also Theme delete option not showing