WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] need some help with a hook (5 posts)

  1. Ovidiu
    Member
    Posted 1 year 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/)

    woocommerce_bacs_icon

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

    http://wordpress.org/extend/plugins/woocommerce/

  2. Max Rice
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

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

  4. Max Rice
    Member
    Posted 1 year ago #

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

  5. Ovidiu
    Member
    Posted 1 year 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

About this Topic