[resolved] need some help with a hook (5 posts)

  1. Ovidiu
    Posted 3 years ago #

    I would like to change some "wording" on the inside of woocommerce namely on the BACS payment I'd like to change "Sort Code" into "Branch Code".

    I found where the text comes from, its contained within woocommerce/classes/gateways/bacs/class-wc-bacs.php but I want to avoid hacking the core files of this plugin.

    the line looks like this:

    'sort_code' => array(
                                                            'title' => __( 'Sort Code', 'woocommerce' ),
                                                            'type' => 'text',
                                                            'description' => '',
                                                            'default' => ''

    The right hook would be (as found here: http://wcdocs.woothemes.com/codex/extending/hooks/)


    But I have no idea how to code a snippet for my functions.php to do this change.


  2. Max Rice
    Posted 3 years ago #

    Try this in your functions.php:

    add_filter( 'woocommerce_bacs_fields', 'wc_tweak_bacs_sort_code_label' );
    function wc_tweak_bacs_sort_code_label( $fields ) {
    	$fields['sort_code'] = 'Branch Code';
    	return $fields;
  3. Ovidiu
    Posted 3 years ago #

    thanks, just gave it a try and that didn't work.

  4. Max Rice
    Posted 3 years ago #

    Do you want to change this within the Admin section or on the Thank You page?

  5. Ovidiu
    Posted 3 years ago #

    I got the solution on the themehybrid forums:

    add_filter( 'gettext', 'my_gettext', 10, 3 );
    function my_gettext( $translation, $text, $domain ) {
    	if ( 'woocommerce' === $domain ) {
    		$translations = &get_translations_for_domain( $domain );
    		if ( 'Sort Code' === $text )
    			$translation = $translations->translate( 'Branch Code' );
    	return $translation;

    works in the admin AND the thank you page AND in the emails sent out :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic