【发布时间】:2016-11-06 03:39:28
【问题描述】:
我想知道是否可以像 mytheme/includes/bacs/class-wc-gateway-bacs.php 中的模板文件一样更改 woocommerce/includes/bacs/class-wc-gateway-bacs.php?此刻我更改了插件核心中的代码,但更新后它会再次更改。
或者也许有人知道如何在 function.php 文件中使用钩子或类似的东西来做到这一点?
我需要改变这个功能:
/**
* Get bank details and place into a list format.
*
* @param int $order_id
*/
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->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 );
if ( ! empty( $bacs_accounts ) ) {
echo '<h2 class="wc-bacs-bank-details-heading">' . __( 'Our Bank Details', 'woocommerce' ) . '</h2>' . PHP_EOL;
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
if ( $bacs_account->account_name || $bacs_account->bank_name ) {
echo '<h3>' . wp_unslash( implode( ' - ', array_filter( array( $bacs_account->account_name, $bacs_account->bank_name ) ) ) ) . '</h3>' . PHP_EOL;
}
echo '<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(
'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'] ) ) {
echo '<li class="' . esc_attr( $field_key ) . '">' . esc_attr( $field['label'] ) . ': <strong>' . wptexturize( $field['value'] ) . '</strong></li>' . PHP_EOL;
}
}
echo '</ul>';
}
}
}
我真的需要帮助,提前谢谢你:)
【问题讨论】:
-
为什么不创建自定义付款方式,取消设置第一个 Bac 付款方式...尝试在 google 中搜索类似以下搜索:“如何取消设置 BACS”或“woocommerce 取消设置付款方式”和“ woocommerce 自定义付款方式”。然后你可以从 class-wc-gateway-bacs.php 中获取一些代码......只是一个建议。
-
谢谢你,你给了我正确的方法。我创建了具有类似功能但变量不同的插件,它现在可以工作了;)@LoicTheAztec
-
@LoicTheAztec 完成。我不知道如何正确解释,但我已经尽力了
标签: php wordpress woocommerce