Cinder
Cinder

Reputation: 349

WooCommerce: How to change "Our Bank Details" heading?

In the email WooCommerce sends to customers if they ordered a product and picked bank transfer (BACS) as payment method, by default there is an h2 heading: "Our bank details". I want to change this wording.

enter image description here

I figure I best do this via functions.php, but I am not sure how to address this. Could someone please help me?

Alternative approaches to solve this problem are welcome, too.

The line I want to change is in this if-statement in class-wc-gateways-bacs.php:

if ( $has_details ) { echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';

Here is the complete function from within the class WC_Gateway_BACS extends WC_Payment_Gateway:

private function bank_details( $order_id = '' ) {

    if ( empty( $this->account_details ) ) {
        return;
    }

    // Get order and store in $order.
    $order = wc_get_order( $order_id );

    // Get the order country and country $locale.
    $country = $order->get_billing_country();
    $locale  = $this->get_country_locale();

    // Get sortcode label in the $locale array and use appropriate one.
    $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );

    $bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details, $order_id );

    if ( ! empty( $bacs_accounts ) ) {
        $account_html = '';
        $has_details  = false;

        foreach ( $bacs_accounts as $bacs_account ) {
            $bacs_account = (object) $bacs_account;

            if ( $bacs_account->account_name ) {
                $account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
            }

            $account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;

            // BACS account fields shown on the thanks page and in emails.
            $account_fields = apply_filters(
                'woocommerce_bacs_account_fields',
                array(
                    'bank_name'      => array(
                        'label' => __( 'Bank', 'woocommerce' ),
                        'value' => $bacs_account->bank_name,
                    ),
                    'account_number' => array(
                        'label' => __( 'Account number', 'woocommerce' ),
                        'value' => $bacs_account->account_number,
                    ),
                    'sort_code'      => array(
                        'label' => $sortcode,
                        'value' => $bacs_account->sort_code,
                    ),
                    'iban'           => array(
                        'label' => __( 'IBAN', 'woocommerce' ),
                        'value' => $bacs_account->iban,
                    ),
                    'bic'            => array(
                        'label' => __( 'BIC', 'woocommerce' ),
                        'value' => $bacs_account->bic,
                    ),
                ),
                $order_id
            );

            foreach ( $account_fields as $field_key => $field ) {
                if ( ! empty( $field['value'] ) ) {
                    $account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
                    $has_details   = true;
                }
            }

            $account_html .= '</ul>';
        }

        if ( $has_details ) {
            echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
        }
    }

}

Upvotes: 1

Views: 1551

Answers (1)

Rajat Sharma
Rajat Sharma

Reputation: 161

Please try this

function update_bank_details_heading($translated_text, $text, $domain) {

   if ( did_action('woocommerce_email_before_order_table') ) {

        switch ( $text ) {

            case 'Our bank details' :

                $translated_text = __( 'Bank Details Are...', 'woocommerce' );
                break;

        }

    }

    return $translated_text;
}

add_filter( 'gettext', 'update_bank_details_heading', 20, 3 );

Upvotes: 1

Related Questions