将 wooCommerce 订单号复制到“收到的订单结账”页面的语法

问题描述 投票:0回答:1

woo 订单号已显示在“已收到订单”页面顶部附近,位于“您的订单已收到...”行下方。

我们的大多数客户使用“直接银行转账”(又名“BAC”付款方式)付款。 给客户的说明要求他们重新使用订单号作为参考字段,即当他们将详细信息输入银行系统时。但我们希望通过在显示银行详细信息时将订单号复制到(新创建的)“参考”字段来改进这一点。例如

 BANK:      SORT CODE:  ACCOUNT NUMBER:   REFERENCE:   IBAN:  BIC:  
 myBank     00-00-00   12345678    12345678          T1234        ...    ...

我们有工作代码(如下所示)来显示 BAC 详细信息,但尚未找到插入 woo 订单号的正确语法(其前缀为一个文本字符。)

add_filter('woocommerce_bacs_account_fields','custom_bacs_fields');

function custom_bacs_fields() {
global $wpdb;
$account_details = get_option( 'woocommerce_bacs_accounts',
array(
   array(
    'account_name'   => get_option( 'account_name' ),
    'sort_code'      => get_option( 'sort_code' ),
    'bank_name'      => get_option( 'bank_name' ),
    'account_number' => get_option( 'account_number' ),
    'iban'           => get_option( 'iban' ),
    'bic'            => get_option( 'bic' )
   )
)
);

$account_fields = array(
'bank_name'      => array(
    'label' => 'Bank',
    'value' => $account_details[0]['bank_name']
),
'sort_code' => array(
    'label' => __( 'Sort Code', 'woocommerce' ),
    'value' => $account_details[0]['sort_code']
),
'account_number' => array(
    'label' => __( 'Account Number', 'woocommerce' ),
    'value' => $account_details[0]['account_number']
),
'ref' => array(
    'label' => __( 'Ref', 'woocommerce' ),
    'value' => 'qwerty' //  $order[0]->get_order_number()  << syntax for this needed
),  
    
'iban' => array(
    'label' => __( 'iban', 'woocommerce' ),
    'value' => $account_details[0]['iban']
),
'bic' => array(
    'label' => __( 'bic', 'woocommerce' ),
    'value' => $account_details[0]['bic']
)
);
 return $account_fields;
}

--------------------第二次尝试--------------------

按照建议,我尝试将订单号传递到函数中,然后打印它以了解其内容:

add_filter('woocommerce_bacs_account_fields','custom_bacs_fields');

function custom_bacs_fields( $order ) {
   print_r( $order );
   //$order_id  = $order->get_id(); // Get the order ID
global $wpdb;
...

但是它打印为 BACs 数组!!:(我哪里出错了?)

Array ( [bank_name] => Array ( [label] => 银行 [value] => MyBank ) [account_number] => Array ( [label] => 帐号 [value] => 01234567 ) [sort_code] => Array ( [标签] => 排序代码 [值] => 00-00-00 ) [iban] => 数组 ( [标签] ... 等等 ) )

php hook-woocommerce
1个回答
0
投票

这是有效的解决方案:(添加到我们的子 php 文件中)

add_filter('woocommerce_bacs_account_fields','custom_bacs_fields');

function custom_bacs_fields( $new_order_id ) {
    global $new_order_id;       // needs to be global, defined earlier when 'P' prefixed to the Order No.,
        //  debug_to_console( $new_order_id );
    global $wpdb;
$account_details = get_option( 'woocommerce_bacs_accounts',
array(
   array(
    'account_name'   => get_option( 'account_name' ),
    'sort_code'      => get_option( 'sort_code' ),
    'bank_name'      => get_option( 'bank_name' ),
    'account_number' => get_option( 'account_number' ),
    'iban'           => get_option( 'iban' ),
    'bic'            => get_option( 'bic' ),
   )
)
);

$account_fields = array(
'bank_name'      => array(
    'label' => 'Bank',
    'value' => $account_details[0]['bank_name']
),

'sort_code' => array(
    'label' => __( 'Sort Code', 'woocommerce' ),
    'value' => $account_details[0]['sort_code']
),

'account_number' => array(
    'label' => __( 'Account Number', 'woocommerce' ),
    'value' => $account_details[0]['account_number']
),
    
'ref' => array(
    'label' => __( 'Reference', 'woocommerce' ),
    'value' => $new_order_id    
),  
    
'iban' => array(
    'label' => __( 'iban', 'woocommerce' ),
    'value' =>  $account_details[0]['iban']
),
    
'bic' => array(
    'label' => __( 'bic', 'woocommerce' ),
    'value' => $account_details[0]['bic']
),
);
 return $account_fields;
} 

/* end of function   */
© www.soinside.com 2019 - 2024. All rights reserved.