Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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