I want to change the add to cart text on product archives on specific categories only. For example, on preorder category i want instead of add to cart
text, to be Preorder
. I don't know how to identify Preorder category in the below function.
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // < 2.1
function woo_archive_custom_cart_button_text() {
return __( 'Preorder', 'woocommerce' );
}
It can be 2 different things (as your question is not so clear)…
1) To target products on a specific product category archive pages you should use the conditional function
is_product_category()
this way:Code goes in function.php file of the active child theme (or active theme).
2) To target a specific product category on Woocommerce archives pages you will use
has term()
this way:For single product pages you will use additionally this:
Code goes in function.php file of the active child theme (or active theme).
Tested and works.
Related answer: Targeting product terms from a custom taxonomy in WooCommerce
Related docs: Woocommerce Conditional Tags
You can use has_term() with condition. Updated code is as below.
Solution- 1. Using filter
add_to_cart_text
Solution- 2. Using filter
woocommerce_product_add_to_cart_text
where
your-special-category
will your category for which you want to replaceadd to cart
text.