Created
July 6, 2014 04:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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