is_category()
only check the built in post category. Product categories are custom taxonomies. So you need to use is_tax()
instead of is_category()
and get_term()
instead of get_category()
.
Check this example:-
function is_subcategory($cat_id = null) {
if (is_tax('product_cat')) {
if (empty($cat_id)){
$cat_id = get_queried_object_id();
}
$cat = get_term(get_queried_object_id(), 'product_cat');
if ( empty($cat->parent) ){
return false;
}else{
return true;
}
}
return false;
}
Also safe side instead of get_query_var()
use get_queried_object_id()
Related Posts:
- Display Categories Assigned to a WooCommerce Product
- How to show “Previous Category” and “Next Category” in categories archieve template [closed]
- get deepest Woocommerce Product Category on Archivepage
- woocommerce – how to get product link by id
- Display data when category is empty
- I’m trying to display product categories on each product in the list
- Category with description and thumbnail
- Add category description on product page (Woocommerce)
- Link Back to Parent Category – Woocommerce
- how to use wc_create_order with subscription product
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Add custom variable to cart content [closed]
- Programmatically create product category and add thumbnail in woocommerce
- WooCommerce changes lost password reset link
- WooCommerce Change Product Global Attribute Value via CRUD for Simple Product [closed]
- When Free shipping is available hide other shipping methods except Local pickup in WooCommerce [closed]
- get_terms won’t display product_cat or any other custom taxonomies when specified
- Woocommerce Shop Price Position
- WooCommerce WebHook Retry
- Can I set a custom “alt” attribute with woocommerce_get_product_thumbnail()?
- Remove all Span Tags and class From Woocommerce Price [closed]
- Importing Woocommerce products with variations
- Woocommerce login not working on the first try
- Show add to cart button on shop woocommerce
- get current product name in functions.php
- How do I hide the purchase note in the WooCommerce ‘order completed’ email?
- Woocommerce – Override the default templates location under the theme directory
- WOO-Commerce translation | Tried it all [closed]
- Is there a way to show Single Variation prices in the product loop when filters or attributes are active?
- Function to recalculate shipping costs on subscriptions after renewal with Automatewoo
- Creating a multisite registration form that also creates a woocommerce post
- add shoppy.gg to woocommerce instead of add to card [closed]
- List of shipping on product page [closed]
- How to show tag count for individual product post in wordpress woocommerce
- How to edit T&C checker text in Woocommerce checkout page? gettext?
- What is the reason for two classes storefront_woocommerce and storefront
- Get email type inside email template – order emails
- Caption not showing with Woo commerce thumbnails
- Change the Title Tag of Search Products Page
- Confirm Password on checkout page not working in woocommerce 3.0.1
- In WooCommerce can you make a list of ‘steps’ for quantity increase? [closed]
- Adding author option to [products] woocommerce shortcode
- Set dynamic Options array in woocommerce_form_field
- WooCommerce product title formatting
- Redirect no product url’s to static url
- How to modify WooCommerce button text in default and additional languages
- How to hide URL for downloadable product in WooCommerce? [closed]
- Customizing WooCommerce
- Get Post ID from attachment ID (Redirect to product page)
- WooCommerce set a min order price for a single country [closed]
- “Reset my password” links to itself (page refreshes) [closed]
- Woocommerce product tab is not showing probably
- How to list best seller products in woocommerce
- Updating failed. The response is not a valid JSON response. Gutenberg + Woocommerce Products
- Add product image to Woocommerce downloads page
- Woocommerce only display child category when parent is checked (on add new product page)
- How to check if woocommerce_order_item_name is use in email?
- Sharing data between filters on a snippet (user specific) for Woocommerce
- How to add custom checkboxes from loop to WooCommerce product variation options?
- Restrict product tags archive to certain users
- Logo showing on some page but not on product categories pages
- Categories on attribute archive pages
- Woocommerce Product Variation – Add Price Logic
- Display related product categories by subcategory
- In if…else condition, the else statement shows even if if statement is correct
- Woocommerce Multisite global search how to mod ajax function?
- How to let users create lists of woocommerce products?
- How to force Woocommerce to deliver the product to the paypal adress which was used?
- Order again Woocommerce inside View Order
- Photo cover in WooCommerce
- How to vary WooCommerce product prices based on order dates
- How to save one API response to WooCommerce order meta data
- WooCommerce and ACF: How to Redirect Upon Add to Cart – Partially Working Example
- Woocommerce: Search by custom attribute
- Set Post Thumbnail to external URL
- Restrict retrieved terms by category?
- Custom theme woocommerce product detail page template not working
- Increase the download speed of a large number of variations in WooCommerce
- remove add to cart for free (0 $) product woocommerce
- merge tabs in woocommerce
- WooCommerce: Adding a setup fee to certain products
- Removing shipping for one product with coupon
- Awesome Support Custom Field for show Woocommerce orders
- How to make a custom redirect in WooCommerce?
- Firstname and lastname greyout or hidden Billing details at next checkout like username is hidden [closed]
- Site with WooCommerce section moved to HTTPS – all pages except home and main store are 404s
- Multiple quantities with options
- how to add custom reviews button in woocommerce order complete generated mail
- Not all strings are translated
- Woocommerce – get product in category with specific attribute
- Woocommerce make appear when items added to cart
- Testimonials/Reviews for Products
- add custom menu in woocommerce dashboard [closed]
- Get all categories
- Updating order meta to have a meta entry from an item in the order
- Adding a column to woocomerce admin order page that can be sorted
- WordPress error
- Auto generating API keys using the Application Authentication Endpoint [closed]
- Is there a way to conditionally check if i’m on product variation page url like mydomain.com/myproduct?attribute_pa_color=red
- Add custom ID to WooCommerce product tab