-1

In WooCommerce, I am looking for a function to change the "Place Order" text if cart has a specific product(ID) on checkout page.

This is useful for woo shops selling product and at the same time offering different services for example memberships. This will make the place order text more descriptive of the product as a Call to Action button.

I founded that function for change ‘add to cart' button text on single product page based on specific product id

add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); 

function woo_custom_cart_button_text( $text ) {
  global $product;

  if ( 123 === $product->id ) {
    $text = 'Product 123 text';
  }
  return $text;
}

And changing the place order text globally;

add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' ); 

function woo_custom_order_button_text() {
    return __( 'Your new button text here', 'woocommerce' ); 
}

Im looking for how to adapt them for checkout page.

Thanks.

0

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' ); 
}
  • Hello, thanks for answer. Where i should add is_page condition for woo_custom_order_button_text function? May you please give an example for functions.php or page header others else. Thanks so much. – OnurK. Dec 27 '16 at 13:25
  • I've updated my answer. – Jami Gibbs Dec 27 '16 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.