Woocommerce:将自定义字段添加到BACS帐户详细信息页面

时间:2020-10-23 00:13:22

标签: php wordpress woocommerce hook hook-woocommerce

请大家

1°我正在尝试为BACS帐户详细信息页面(管理区域)创建一个自定义字段,因此我可以在我的感谢页面中显示并同时发送每封电子邮件。 / p>

2°我正在遵循本文的内容,但我认为我做的事情不正确

https://docs.wpdebuglog.com/plugin/woocommerce/4.0.0/filter/woocommerce_bacs_account_fields/

3°刷新页面时,我在debug.log文件中收到如下错误消息:

C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1853
[22-Oct-2020 21:04:51 UTC] PHP Parse error:  syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting variable (T_VARIABLE) in C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1853

[22-Oct-2020 21:04:51 UTC] PHP Parse error:  syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting variable (T_VARIABLE) in C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1853

[22-Oct-2020 21:06:18 UTC] PHP Parse error:  syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting variable (T_VARIABLE) in C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1853

[22-Oct-2020 23:39:06 UTC] PHP Parse error:  syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting variable (T_VARIABLE) in C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1853

这是1853行

function custom_woocommerce_bacs_account_fields( $array, value => $bacs_account_bank_name), account_number => array, value => $

4°我也尝试了本文中的示例,但是我也收到了错误消息。(有些错误)

http://hookr.io/plugins/woocommerce/3.0.6/filters/woocommerce_bacs_account_fields/#

总而言之,我需要创建一个新的自定义字段,如下所示:

'pid'           => array(
 'label' => __( 'PID', 'woocommerce' ),
 'value' => $bacs_account->pid,
), 

这是我正在尝试的整个脚本-functions.php:

感谢您的帮助!

$account_fields = apply_filters(
                    'woocommerce_bacs_account_fields',
                    array(
                        'account_name'      => array(
                            'label' => __( 'Nome da Conta', 'woocommerce' ),
                            'value' => $bacs_account->account_name,
                        ),
                        'account_number' => array(
                            'label' => __( 'Account number', 'woocommerce' ),
                            'value' => $bacs_account->account_number,
                        ),                    
                        'bank_name'      => array(
                            'label' => __( 'Nome Banco', 'woocommerce' ),
                            'value' => $bacs_account->bank_name,
                        ),
                        'bank_agency'      => array(
                            'label' => __( 'Agencia', 'woocommerce' ),
                            'value' => $bacs_account->bank_agency,
                        ),
                        'sort_code'      => array(
                            'label' => $sortcode,
                            'value' => $bacs_account->sort_code,
                        ),
                        'pid'           => array(
                            'label' => __( 'PID', 'woocommerce' ),
                            'value' => $bacs_account->pid,
                        ),
                        'iban'           => array(
                            'label' => __( 'IBAN', 'woocommerce' ),
                            'value' => $bacs_account->iban,
                        ),
                        'bic'            => array(
                            'label' => __( 'BIC', 'woocommerce' ),
                            'value' => $bacs_account->bic,
                        ),
                    ),
                    $order_id
                );


// define the woocommerce_bacs_account_fields callback 

function custom_woocommerce_bacs_account_fields( $array, value => $bacs_account_bank_name), account_number => array, value => $bacs_account_account_number), sort_code => array, iban => array, value => $bacs_account_iban), bic => array, value => $bacs_account_bic),pid => array, value => $bacs_account_pid)), $order_id ){ 
   //custom code here
    return $array, value => $bacs_account_bank_name), account_number => array, value => $bacs_account_account_number), sort_code => array, iban => array, value => $bacs_account_iban), bic => array, value => $bacs_account_bic), pid => array, value => $bacs_account_pid))
} 

//add the action 
add_filter('woocommerce_bacs_account_fields', 'custom_woocommerce_bacs_account_fields', 10, 2)

1 个答案:

答案 0 :(得分:0)

因此,由于在这种情况下我没有得到任何明确的帮助,因此这里有一个明确的解决方案对我有所帮助。

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);