1

how can i edit the Place order button text in Woocommerce i tried

add_filter('woocommerce_order_button_text','custom_order_button_text',1);
function custom_order_button_text($order_button_text) {

    $order_button_text = 'Complete Checkout';

    return $order_button_text;
}

but it didn't work

1

This question has been answered here.

Basically, you want to use a switch statement hooked to the gettext filter. One benefit of this method is, if you need to change more text down the line you can just add another case to the function. For example:

add_filter( 'gettext', 'wpsx_replace_text_string', 20, 3 );
function wpsx_replace_text_string( $translated_text, $text, $domain ) {

  if ($domain === 'woocommerce') {
    switch ( $translated_text ) {
        //Text to replace
        case 'Place Order' :
            $translated_text = __( 'Complete Checkout', 'woocommerce' );
            break;
        //More text to replace
        case 'Related Products' :
            $translated_text = __( 'Other Options', 'woocommerce' );
            break;
    } 
  }

  return $translated_text;
}
  • This filter hook is applied to the translated text by the internationalization functions (from Codex) and should be avoided for other uses. – Laxmana May 15 '17 at 9:52
  • @Laxmana Which codex entry are you referencing? I could be mistaken however the entry I link to above makes no mention of such a limitation. In fact the examples in it seem to suggest this is an acceptable use. See "Change the Comment Form" and "Remove Text from Admin Form" – DaveLak May 15 '17 at 14:02
  • At the gettext codex entry. What I want to say is that this filter is being called every time a function like _e() or __() is fired. So in a typical theme, and WordPress Admin, this kind of functions could be more than a hundred. So your filter would be fired a lot. Better to use a filter like woocommerce_order_button_text for better performance. – Laxmana May 15 '17 at 15:02

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.