0

i was looking for a way to add a new field to woocommerce bank account info, my theme has no child theme and i put my code in functions.php

I found the solution but it doesn't work.

function newfield_bacs_account_field( $account_fields, $order_id ) {
    $account_fields['test_added' ] = array(
        'label' => __( 'labelfield', 'woocommerce' ),
         'value' => __( 'valuefield', 'woocommerce' ),
    );
    return $account_fields;
}

add_filter( 'woocommerce_bacs_account_fields', 'newfield_bacs_account_field', 10, 2);

i have tried thousands of times but still not working

4
  • Which functions.php?
    – Rup
    Jun 10 at 16:00
  • I'd make sure this code is being loaded and run, e.g. deliberately put a syntax error in the file and see what happens, or error_log() from inside your function and next to the line that adds the filter, or throw new Error("new BACS fields"); in the same places.
    – Rup
    Jun 10 at 16:02
  • You don't need the __() function since that's trying to load translated text from the WooCommerce language pot which won't be there. Instead you can either load the translations from your own namespace (not woocommerce) or just hard-code strings for now.
    – Rup
    Jun 10 at 16:03
  • Also I'm slightly surprised the filter doesn't pass in $bacs_account from the calling code, since all of the default values are read from that, and I guess any new data you've got would be read from or computed from those values as well. Out of interest, what's the new field that you're adding for?
    – Rup
    Jun 10 at 16:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.