Last active
October 30, 2023 10:29
-
-
Save SirDarcanos/2af73b89370369d2b93c to your computer and use it in GitHub Desktop.
Change the “Add to Cart” text on the single product page, conditionally
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
<?php | |
add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_add_to_cart_text', 10, 2 ); | |
function change_add_to_cart_text( $default, $product ) { | |
$terms = get_the_terms( $product->id, 'product_cat' ); | |
foreach ( $terms as $term ) { | |
if ( $term->name == 'Posters' ) { | |
$default = __( 'Custom Text', 'domain' ); | |
break; | |
} | |
} | |
return $default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment