Configure, product_id and parent_category_id according to your requirements.
/* This is product id */
$product_id = 1;
/* This is the id of the parent category */
$parent_category_id = 8;
$cats = get_categories ( array (
'type' => 'product',
'parent' => $parent_category_id,
'orderby' => 'term_group',
'hide_empty' => true,
'hierarchical' = > 1,
'exclude' => '',
'property' => '',
'number' => '',
'taxonomy' => 'product_cat',
'pad_counts' => false
));
$non_empty_sub_categories_ids = array_map(create_function('$cat', 'return $cat->term_id;'), $cats);
$product_cats = get_the_terms( $product_id, 'product_cat' );
foreach ($product_cats as $product_cat) {
if(in_array($product_cat->term_id, $non_empty_sub_categories_ids)) {
echo '<a <br/> href="'. get_term_link($product_cat->slug,' product_cat ').' "> '. $product_cat->name.'</a>';
}
}
Related Posts:
- WooCommerce: How to edit the get_price_html
- Get woocommerce product price by id [closed]
- WooCommerce prices location in DB
- Woocommerce: How to remove page-title at the home/shop page but not category pages
- Preventing WooCommerce email sending only on particular conditions
- Woocommerce view order link in customer emails
- Is is safe to edit language files from wp-content/languages/plugins/woocommerce-ro_RO?
- Display WooCommerce only in stock sizes product attribute on shop page
- Remove “Choose An Option” on Product Variation & Auto Select Instead
- check if current url/page equals checkout page [closed]
- Mini cart in header using divi is not getting updated on changing the cart items count:
- How to stop a Gutenberg Block from firing multiple GET Requests?
- Woocommerce Product Price Inserted programmatically doesn’t get displayed In Single Product Page
- How to Order by random on a SQL query
- Move add to cart in Woocommerce
- Separate Categories from WC Product loop when display type is set to both on the category
- Exclude products with a stock lower than the low stock threshold from the shop loop [closed]
- Remove Order List Row Link in WooCommerce Admin?
- How do I hide out of stock products from homepage but not from catalog?
- Woocommerce order processing email subject not changing
- Different translations for the same plugin inside a multisite
- Woocommerce multiple taxes with same rates adds as different values.
- function to add note on single Woo Commerce product page for downloadable variations
- wp_customize – detect post type to show/hide customizer options
- WooCommerce – Display nested list of all subcategories on archive-product.php
- Woocommerce Porto Theme Hide Selected Categroy for Breadcrumbs
- Set specific number of columns for top level term on product category archives
- Woocommerce REST API – updating an order changes custom tax calculations
- How to list all WC products by their attributes values?
- Showing the WordPress standard text area on a Woocommerce Single Product Page?
- Woocommerce custom search
- How to be able to edit custom address fields in WooCommerce admin?
- WordPress WooCommerce: How to allow only specified customers to pay by check? [closed]
- Make a Read More toggle in the_content on single-product in Woocoomerce
- WooCommerce Base Page Featured Image Custom Theme
- Adding extra email address who receives email like admin – woocommerce
- Is it possible to merge Woocommerce attributes? [closed]
- How can i create a custom product search?
- Can’t remove woocommerce sidebar
- Woocommerce Slow Queries
- How to display the percentage of the applied tax in woocommerce [closed]
- Remove link from product attributes in tab “additional information” [closed]
- Merging updated dev site with live site while keeping orders correct
- Disabling shopping basket in WooCommerce [closed]
- Dynamic Product Variation in WooCommerce
- Get decimal from product price with Mysql
- Woocommerce – Shop page repeat the products with filters
- Woocommerce – Adding row to cart table
- Hide a product with a certain tag from product-category
- Custom rewrite for product variation not working
- Block Disposable Emails on Woocommerce Registration
- Can’t Change WooCommerce Default Language to Spanish (Mexico)
- Adding of custom cart item data via Ajax Add to Cart
- Woocommerce – Display stock quantity per variation
- Apply a custom WooCommerce order status based on user role
- Woocommerce product name [closed]
- Hooks For Design variation in woo commerce single product page
- Dokan stock management
- How to hide order action button after changing order status to completed
- Access custom meta_data in processing order email
- Woocommerce : How to automatically input the same email for every order?
- Woocommerce – Change order of products in Confirmed Order
- echo product parent category
- How to edit wc_get_template_part for archive products
- Deregister dequeue JS scripts except on 1 product page
- Woocommerce – how to round up all prices to end in .99
- Display WooCommerce product attribute on shop page
- How to get product category ID based on post?
- How do I disable “Flat Rate” radio button and remain with other shipping method in woocommerce
- How to add woocommerce product price filter widget to other page
- Remove Stripe Woocommerce Credit Card Icons (and replace with image)
- How to add external product url to woocommerce from a metadata by function.php
- Unable to call woocommerce hook in my custom php file
- Custom account page that accepts a query parameter
- Custom WooCommerce template for product
- Checkout fr Woocommerce – load default WooCommerce checkout template on the fly
- Two types of product categories on shop page
- How to send an automatic email to a custom field in Woocommerce order meta 2 weeks after a product is bought
- Woocommerce cart table too wide [closed]
- HTTP Error when uploading pictures and problem with the size of images
- How does one allow any customer to process any order in store on woocommerce?
- WooCommerce CSV Image URL Creates Additional Images in Media Folder
- Custom changes performed on WP + WooCom site on maintenance subdomain. How to perform a migration to a main domain?
- Woocommerce Child Category Permalink Structure Change
- Allow customer to choose an optional free/paid product to add to their order (and reduce stock reduced & record sale)
- How to restrict type/size of file uploads in any plugin?
- In woocommerce some products have empty options, but how to check this
- WooCommerce – Adding Product Attributes to CSV Export
- How to disable the “Upgrade or Downgrade” button in “My account” of WooCommerce Subscriptions
- WooCommerce – Inconsistent Indexing of Orders
- Woocommerce Add to Cart function
- WooCommerce – doesn’t show product when using woocommerce.php [closed]
- How to show woocommerce login / registration form in modal
- How to dublicate WC Product title to shortdescription field? [closed]
- Translate Woocommerce tab
- Woocommerce -> gallery images per variation without a plugin? [closed]
- Why is my WordPress admin not working
- Create bookings after subscription renewal
- Change variants URL
- Use a woocommerce hook to create a table and populate it with a query