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
- Change filter id into slug
- Set Variant options/attributes values on WooCommerce
- Pagination on Custom Tax Pages Removes Spaces from Query Vars
- Taxonomy Rewrite Rules Redirecting Instead of Masking
- get_terms not returning any custom taxonomies
- I don’t need ‘view’ page for my custom taxonomy
- WordPress implode & wp_insert_post question
- Using WP_Query and Query_post for the loop?
- How to write sql query to get the posts from a custom taxonomy term name
- How to do a particular wp_query taxonomy search
- Multiple Custom Taxonomy Dropdowns Lists
- How to display a custom taxonomy without a link?
- Get post count for current custom taxonomy
- Build filter for post-type + multi taxonomies + multi terms
- get_term_by works but get_terms doesn’t?
- Double slash in the_terms URL
- Using custom taxonomy when registering a new custom post type
- How to call a custom taxonomy term name inside a function?
- Get custom taxonomy name (not the term) in custom post
- How to add custom content to custom taxonomy
- Fix Custom Taxonomy Display two times on each call
- Update Custom Taxonomy Value for a post based on custom date field
- How to output taxonomy term (incl. link to archive) on author.php?
- Featured Images for Tags?
- Taxonomize taxonomy terms?
- displaying posts from a custom post type tags
- Saving custom taxonomies to post as checkbox on frontend
- How can I show links for custom posts group by taxonomy current term and sub-term?
- Show custom taxaomy as a product meta
- Taxonomy page loading wrong data
- How to use custom slug and custom templates for custom taxonomy?
- Updating a custom post type’s custom taxonomy in a custom editor block
- Can I get thumbnail of taxonomy?
- Adding Advanced Custom Fields to posts
- Filter Tags for current users
- Add term to taxonomy programatically
- How to filter a page title with custom taxonomies
- setting a custom post type taxonomy term by code
- Custom TaxonomyTemplate
- Assign a default description to new terms under a custom taxonomy
- Reset custom taxonomy meta data after saving
- How to add a custom user taxonomy column to “All Users” in users.php?
- WordPress Multiple Taxonomy Query
- Custom Taxonomy user based creation
- Order posts with custom taxonomy array
- How to perform a search inside a specific taxonomy category
- Retrieve name or slug from get_objects_in_term
- Exclude 2 in 3 terms of A Taxonomy from all Archives
- register_taxonomy – show in admin menu, but not on post type (edit) screen
- Altering term_id and name via $wpdb class
- Display Parent and child taxonomies in seperate drop downs [duplicate]
- Advanced WordPress search form based on custom taxonomy and custom meta value
- Get Taxonomy and metadata
- More than one Hierarchical Taxonomy and SEO
- Custom Search only for my Custom Taxonomy Page – data
- Child terms with improper parent in the url should redirect to 404
- How to handle custom taxonomy archive when no posts will have that taxonomy
- ACF – How to get custom taxonomy term image field