You can conditionally check for a page with is_page
so that the woo_custom_order_button_text
function only returns for whichever page you specify:
// When any single Page is being displayed.
is_page();
// When Page 42 (ID) is being displayed.
is_page( 42 );
// When the Page with a post_title of "Contact" is being displayed.
is_page( 'Contact' );
// When the Page with a post_name (slug) of "about-me" is being displayed.
is_page( 'about-me' );
/*
* Returns true when the Pages displayed is either post ID 42,
* or post_name "about-me", or post_title "Contact".
* Note: the array ability was added in version 2.5.
*/
is_page( array( 42, 'about-me', 'Contact' ) );
There are different ways that you could apply this. If you’d like to limit it to both the product and page, I might try something like this where checkout
is the page you’d only want the filters to run:
if( is_page( 'checkout' ) ) {
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' );
}
function woo_custom_cart_button_text( $text ) {
global $product;
if ( 123 === $product->id ) {
$text="Product 123 text";
}
return $text;
}
function woo_custom_order_button_text() {
return __( 'Your new button text here', 'woocommerce' );
}