In Woocommerce, I am trying to change the colour of the "Add to cart" button based on the product category that it is in. So far I am able to change the text, however I can't figure out how to pass in a persistant colour value in hash format (e.g. #fffff)
// Change add to cart button text per category
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
function wps_custom_cart_button_text() {
global $product;
$terms = get_the_terms( $product->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat = $term->slug;
break;
}
switch($product_cat) {
case 'clothing';
return __('Order your Clothes', 'your_theme_text_domain' );
default;
return __( 'Order now', 'your_theme_text_domain' );
}
}
Any help appreciated.
Here is a way to change the button text and the button color depending on the product category:
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Solved using CSS to modify the button style without PHP. Calling the class ID of the category assigned and then woocommerce button selector element.
Simply put this in your Additional CSS or Custom CSS section: