Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Last active October 30, 2023 10:29
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 SiR-DanieL/2af73b89370369d2b93c to your computer and use it in GitHub Desktop.
Save SiR-DanieL/2af73b89370369d2b93c to your computer and use it in GitHub Desktop.
Change the “Add to Cart” text on the single product page, conditionally
<?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