Here is the code that solved the problem:
$woo_args = array(
'status' => 'publish',
'limit' => 1,
'stock_status' => 'instock',
'brand' => 99
);
$products = wc_get_products($woo_args);
if (count($products) == 0){
//No product with the custom attribute id=99
}
add_filter('woocommerce_product_data_store_cpt_get_products_query', 'my_handle_custom_query_var', 10, 2);
function my_handle_custom_query_var($query, $query_vars) {
if (!empty($query_vars['brand'])){
$query['tax_query'][] = array(
'taxonomy' => 'pa_brand',
'field' => 'id',
'terms' => $query_vars['brand'],
'operator' => 'IN',
);
}
return $query;
}
Related Posts:
- How to get WooCommerce Product Category Link by ID?
- Approach for saving a product attribute values with a custom UI in a woocommerce+dokan set up [closed]
- Set download limit and expiry for WooCommerce downloadable products in specific categories
- Remove pagination from WooCommerce product categories on admin edit navigation menus
- Taxonomy , subtaxonomy,child taxonomy of a product woocommerce
- Woocommerce custom taxonomies page
- Outputting an array of term meta values in a custom WooCommerce tab?
- Programatically added attribute, set to ‘show on product page’ automatically. Woocommerce [closed]
- Get child product categories from parent product category in WooCommerce
- Top level parent taxonomy ID
- Woocommerce product search result layout page
- Filter WooCommerce admin products list by a custom taxonomy
- Woocommerce: How to change the add to cart text in a certain category? [closed]
- Catchable fatal error on custom category post
- Get custom category image from menu
- Hide product categories and taxonomy terms in menu if empty
- Display related products based on 2 specific product attributes values in WooCommerce
- How to target parent product category and its children using WooCommerce?
- woocommerce custom product category template
- Getting WooCommerce product related child categories
- Hiding taxonomies with no children WP_Query & tax_query
- How to display ACF taxonomy checkbox links on WooCommerce product category archive
- Hide custom Woocommerce taxonomies when empty
- Add attribute taxonomy through code don’t appear in admin product page
- Showing custom taxonomy in woocommerce signle product page
- Adding term to a custom taxonomy based on term from product category
- Warning: Undefined variable $post in C:\xampp\htdocs\… after PHP upgrade
- Admin only taxonomies?
- Fill New Taxonomies
- Infinite Scroll appending Next Product Category Term pages
- How to exclude woocommerece product category in search results?
- Cloning product not copying custom taxonomies
- how to show product custom taxonomies in woocommerce rest api
- WordPress search form and search result through ACF field in custom taxonomy
- Get user created Woocommerce attributes ( taxonomies ) [closed]
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- How do you search for a post by custom taxonomy?
- Display woocommerce product_cat child terms with thumbnails
- Woocommerce – how to get and display selected variations on single product page
- How do I check if a post has a term with a particular ancestor/parent?
- Creating a custom archive page for WooCommerce products based on tags
- Hide empty categories on widget
- Remove taxonomy base or term from url
- Bulk term assignment for attachment taxonomies
- Taxonomy slug by term ID
- Create taxonomy with meta term using the WP Rest Api
- Best practices for complex taxonomies
- wp_get_object_terms – How can I order the resulting array by hierarchy?
- How to output the taxonomy term name in a widget
- custom post type category page
- Advanced custom fields – taxonomy terms images [closed]
- Is It Possible To Have Shared WordPress Custom Post Types?
- How do I make a custom taxomony appear like tags?
- How can I conditionally change the title of a taxonomy meta box?
- meta_key & meta_value not working with get_pages and custom taxonomy
- Display sub categories and their data of a taxonomy
- Add multiple taxonomy filters to edit.php that support search
- Extend & Search Native WordPress Image Galleries With Tags and Taxonomies?
- Set taxonomy fields on post with AJAX
- A way to query custom taxonomies by name
- Custom Taxonomy index/archive hierarchy
- Show related posts that match two categories
- Hierarchical Taxonomy Terms Select Menu Output with selected=”selected” Set
- Sorting Custom Posts on Archive page with pagination
- Removing “s” from search with custom parameters
- Search Query for Multiple Terms In Same Taxonomy
- How to Modify Default Text in a Custom Taxonomy Admin Panel?
- Problem with wordpress pagination
- Why isn’t the ‘no results’ being shown when a query returns no results?
- How to get_the_term_list() from multiple taxonomies?
- link directly to custom post if there is only one in the taxonomy
- Show only the sub-categories (and their content) of the current custom taxonomy with ‘taxonomy.php’
- How to get custom post type categories in an array
- WordPress modify Settings > Permalinks (options-permalink.php) Add CPT Permalink Options
- How do I make multiple dependent input fields that use the jquery autocomplete function?
- Also show terms that are related to draft and pending posts
- Displaying Posts Attached to Custom Taxonomy Terms
- Update Post Taxonomy Automatically Based On Date
- Custom taxonomy page not working
- What is the best way to change sidebars based on custom taxonomy terms?
- Displaying the post count of all custom taxonomy terms in a list format
- Automatically tag posts based on user-defined words [closed]
- How to update post taxonomies (Creating a custom UI for Custom Taxonomy)
- Taxonomy dropdown metabox in the back-end
- Taxonomy archive uses incorrect template when query strings are used
- wordpress mysql / wpdb ajax load more for terms help
- Get child product categories from parent product category for CUSTOM TAXONOMY archive page
- Get children of taxonomies
- Auto add custom taxonomy to permalink when save
- Custom taxonomy – no posts found
- WP Tax query & order by tax query not working
- Custom button on custom taxonomy listing page
- Custom Taxonomy Archives Page Errors
- Permalink Rewrite to include Custom Taxonomy Term
- Where is defined a custom register_taxonomy? [closed]
- Multiple Taxonomy in URL/Query – No Custom Post Type
- Displaying Custom Taxonomy List Posts By Slug?
- Show different sidebar on taxonomy pages when a default is set
- How can I get parent term from a child term
- ACF Display Taxonomy Image Field