Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.