Skip to content

Instantly share code, notes, and snippets.

@craiggrella
Created July 6, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craiggrella/d0e1cc138f9ee93cd09e to your computer and use it in GitHub Desktop.
Save craiggrella/d0e1cc138f9ee93cd09e to your computer and use it in GitHub Desktop.
Changes the add to cart text on woo commerce single products filtering by product category.
/* CHANGE ADD TO CART BUTTON TEXT ON A PER PRODUCT BASIS
**********************************************************/
add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
if ( is_singular('product') ) {
global $post;
$donations_slug = 'donation';
// get categories
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $cats_array[] = $term->slug;
if (in_array($donations_slug, $cats_array)) {
return __('Donate Now', 'woocommerce');
} else {
return __('Add to Cart' , 'woocommerce');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment