You can use the has_term
function to check for the desired term.
function add_cart_button_replace() {
global $product;
$link = $product->get_permalink();
$button_text = __('+show OFFER', 'woocommerce');
// check if the current product has a "product-category" of "free-products"
if(has_term('free-products', 'product_cat', $product->get_id()))
$button_text = __('+choose me', 'woocommerce');
echo do_shortcode('<a href="'.$link.'" class="button addtocartbutton">' . $button_text . '</a>');
}
You can also learn more about has_term
function.
Update: change product-category
taxonomy to product_cat
as per your comment.
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
- 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
- Check if any available product has specific attribute
- 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
- Contact Form 7 – Populate Select List With Taxonomy [closed]
- How To Change Custom Taxonomy To Radio Buttons
- Front End Post Save Child terms
- Page queried instead of a custom taxonomy
- Pros and cons of using [taxonomy name] in place of [category name]?
- Custom Taxonomy terms with latest post ordered by date pagination issue
- drop-down list another query
- Echo taxonomy term meta on author.php
- custom taxonomy archive permalink shows 404 error
- is there any limit of length on creating custom taxonomies?
- WordPress renames slug of tags used in multiple taxonomies?
- How to get a list of taxonomy terms which are being used only within certain post types?
- Taxonomies: display hierarchical parent list
- Custom taxonomies as product variations
- Display an image instead of tag name?
- Print terms with taxonomy and metabox value
- List taxonomies according to whether this post is in another taxonomy in taxonomy archive
- get_category_link returning page URL
- Show preset taxonomy description
- How do I modify taxonomy term slugs dynamically?
- Getting associated taxonomies
- Custom taxonomy not appearing in menu administration panel
- Does using custom taxonomy is more CPU efficient than using meta_data?
- how can i display taxonomy instead of category on my web page?
- Taxonomy Meta Box in User Profile?
- How can I make front page to display custom taxonomy page?
- How to show post list based on taxonomy term?
- WordPress autocomplete search with taxonomies
- Display empty custom taxonomies differently than with one with posts
- remove term from custom taxonomy list
- Display taxonomy with a maximum number of letters
- query to use to link to taxonomy single page
- Dropdown list of taxonomies won’t display selected
- Display Child Categories of Current Post ID
- Taxonomies specific to Page attribute template
- Custom taxonomies registered via plugin stop existing after function finishes running
- Echo ACF taxonomy field within a foreach for another taxonomy
- Keeping session instance of random display results over pagination breaks
- Rewrite Search URL Permalink For CPT Custom Taxonomies
- How can I rewrite the URL of my custom taxonomy to include the year?
- Query Product categories what have a custom field
- Listing Cities A custom taxonmy by selection order
- Template taxonomy-{taxonomy}.php doesn’t show my posts
- Count tags for current post and save into custom meta field (and update it on post edit)
- Problem registering custom taxonomy
- Limit Tag Links in Post Content
- Passing taxonomy id of taxonomy clicked on one page to another page
- Custom Taxonomy Not Being Recognized by is_tax()
- How to truncate the description in the admin panel for a custom taxonomy
- Permalinks incorrectly inserting multiple categories
- customize taxonomy Page
- Why is it defaulting to “uncategorized” even after I select a custom taxonomy
- Get one custom taxonomy category
- Creating a page for custom taxonomy archive
- WordPress Taxonomy Menu
- Insert code on specific taxonomy archives
- get_term_children specific no id
- custom texonomy category child category list with parent head