【发布时间】:2019-08-05 20:50:21
【问题描述】:
根据我的一个问题的“Select BACS account to show in thankyou page in WooCommerce”答案代码,我更改了 Woocommerce 核心文件“class-wc-gateway-bacs.php”为了选择在感谢页面上显示的正确银行帐户,即与已购买产品的变体属性相匹配。
我已在第 255 行之后将下一个代码添加到“class-wc-gateway-bacs.php”:
foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");};
if ( $bacs_account->sort_code != $sede ) { continue; };
所以修改bank_details()函数的代码部分,结果如下:
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");};
if ( $bacs_account->sort_code != $sede ) { continue; };
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>';
}
但是,这不是一个好习惯,我想使用挂钩函数代替 class-wc-gateway-bacs.php。
任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce payment-method