gpt4 book ai didi

php - Woocommerce BACS 支付网关帐户详细信息修改

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:59 28 4
gpt4 key购买 nike

我想知道是否可以像 mytheme/includes/bacs/class-wc 中的模板文件一样更改 woocommerce/includes/bacs/class-wc-gateway-bacs.php -gateway-bacs.php?此时我更改了插件核心中的代码,但更新后它会再次更改。

或者也许有人知道如何在 function.php 文件中使用 hook 或类似的东西来做到这一点?

我需要改变这个功能:

/**
* 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>';
}
}

}

我真的需要帮助,提前谢谢你:)

最佳答案

问题解决:

我刚刚创建了额外的文件 filename.php ,插入了钩子(Hook) + 默认 woocommerce/includes/bacs/class-wc-gateway-bacs.php 代码,改变了$this->id = 'bacs';$this->id = 'YOUR ID NAME'; 并用“bacs 更改所有变量>”到“您的 ID 名称”。该文件转到插件文件夹并在 wordpress 中激活它:)

Full code example jsfiddle

<?php
/*
Plugin Name: Custom Payment Gateway
Description: Custom payment gateway
Author: Baivaras
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

/**
* Custom Payment Gateway.
*
* Provides a Custom Payment Gateway, mainly for testing purposes.
*/
add_action('plugins_loaded', 'init_custom_gateway_class');
function init_custom_gateway_class(){

class WC_Gateway_Custom extends WC_Payment_Gateway {

public $domain;

/* class-wc-gateway-bacs.php from public function __construct CODE GOES HERE */
}
}

add_filter( 'woocommerce_payment_gateways', 'add_custom_gateway_class' );
function add_custom_gateway_class( $methods ) {
$methods[] = 'WC_Gateway_Custom';
return $methods;
}

如果有什么不对,请原谅我的英语:)

关于php - Woocommerce BACS 支付网关帐户详细信息修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38184149/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com