Skip to content

Instantly share code, notes, and snippets.

@woogist
Created July 31, 2015 12:14
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 woogist/8a200b55f6b785b4b4e8 to your computer and use it in GitHub Desktop.
Save woogist/8a200b55f6b785b4b4e8 to your computer and use it in GitHub Desktop.
Change the "Add to Cart" text on the single product page based on the product ID
/**
* Change the "Add to Cart" text on the single product page based on the product ID
*
* @param string $text
* @param object $product
* @return string
*/
function wc_custom_single_addtocart_text( $text, $product ) {
$products = array( 1, 2, 3 );
if ( in_array( $product->id, $products) ) {
$text = 'Special text';
}
return $text;
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_custom_single_addtocart_text', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment