如何在 Woocommerce 中获取和显示 BACS 帐户详细信息
How to get and display BACS account details in Woocommerce
我有一个很简单的想法,但我不知道如何在 WooCommerce 中实现。
在我的商店中,我启用了一些付款选项,也可以通过银行转帐付款。但是当客户选择银行转账时,他会看到进行转账所需的数据。但在那之后,没有选项可以在感谢页面上显示该数据,每个人都在寻找该数据。
有一种简单的方法可以再次显示该数据吗?
在感谢页面上使用操作,在您的 child functions.php 或使用代码片段插件
add_action('woocommerce_thankyou', 'customThankYouFunction');
并在你的function
中写下你的逻辑
function customThankYouFunction ($order_id) {
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
}
您现在可以处理订单了
引用
Bacs 帐户详细信息存储在 wp_options
table 中,就像大多数 Wordpress 和 Woocommerce 设置一样。
可以使用访问它们(它给出了不同银行账户的多维数组,你可以设置很多):
$bacs_accounts_info = get_option( 'woocommerce_bacs_accounts');
通常,此详细信息默认显示在 woocommerce 谢谢页面和一些客户电子邮件通知中……
为了显示格式化的银行账户信息,我构建了这个自定义函数:
// Utility function, to display BACS accounts details
function get_bacs_account_details_html( $echo = true, $type = 'list' ) {
ob_start();
$gateway = new WC_Gateway_BACS();
$country = WC()->countries->get_base_country();
$locale = $gateway->get_country_locale();
$bacs_info = get_option( 'woocommerce_bacs_accounts');
// Get sortcode label in the $locale array and use appropriate one
$sort_code_label = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
if( $type == 'list' ) :
?>
<div class="woocommerce-bacs-bank-details">
<h2 class="wc-bacs-bank-details-heading"><?php _e('Our bank details'); ?></h2>
<?php
$i = -1;
if ( $bacs_info ) : foreach ( $bacs_info as $account ) :
$i++;
$account_name = esc_attr( wp_unslash( $account['account_name'] ) );
$bank_name = esc_attr( wp_unslash( $account['bank_name'] ) );
$account_number = esc_attr( $account['account_number'] );
$sort_code = esc_attr( $account['sort_code'] );
$iban_code = esc_attr( $account['iban'] );
$bic_code = esc_attr( $account['bic'] );
?>
<h3 class="wc-bacs-bank-details-account-name"><?php echo $account_name; ?>:</h3>
<ul class="wc-bacs-bank-details order_details bacs_details">
<li class="bank_name"><?php _e('Bank'); ?>: <strong><?php echo $bank_name; ?></strong></li>
<li class="account_number"><?php _e('Account number'); ?>: <strong><?php echo $account_number; ?></strong></li>
<li class="sort_code"><?php echo $sort_code_label; ?>: <strong><?php echo $sort_code; ?></strong></li>
<li class="iban"><?php _e('IBAN'); ?>: <strong><?php echo $iban_code; ?></strong></li>
<li class="bic"><?php _e('BIC'); ?>: <strong><?php echo $bic_code; ?></strong></li>
</ul>
<?php endforeach; endif; ?>
</div>
<?php
else :
?>
<h2><?php _e( 'Account details', 'woocommerce' ); ?>:</h2>
<table class="widefat wc_input_table" cellspacing="0">
<thead>
<tr>
<th><?php _e( 'Account name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank name', 'woocommerce' ); ?></th>
<th><?php echo $sort_code_label; ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody class="accounts">
<?php
$i = -1;
if ( $bacs_info ) {
foreach ( $bacs_info as $account ) {
$i++;
echo '<tr class="account">
<td>' . esc_attr( wp_unslash( $account['account_name'] ) ) . '</td>
<td>' . esc_attr( $account['account_number'] ) . '</td>
<td>' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '</td>
<td>' . esc_attr( $account['sort_code'] ) . '</td>
<td>' . esc_attr( $account['iban'] ) . '</td>
<td>' . esc_attr( $account['bic'] ) . '</td>
</tr>';
}
}
?>
</tbody>
</table>
<?php
endif;
$output = ob_get_clean();
if ( $echo )
echo $output;
else
return $output;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。测试和工作。
可能的用法:
1) 在任何模板或 php 代码中 您将仅用于显示此帐户详细信息:
get_bacs_account_details_html();
2) 作为挂钩函数(您将在其中设置所需的操作挂钩)。
下面是一个示例用法,它将在我的帐户订单视图中显示此银行帐户详细信息,用于将 BACS 作为支付网关和“暂停”状态的订单:
add_action( 'woocommerce_view_order', 'display_bacs_account_details_on_view_order', 5, 1 );
function display_bacs_account_details_on_view_order( $order_id ){
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
if( $order->get_payment_method() === 'bacs' && $order->get_status() === 'on-hold' ){
get_bacs_account_details_html();
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效。
作为简码 [bacs_account_details]
:
add_shortcode('bacs_account_details','shortcode_bacs_account_details');
函数 shortcode_bacs_account_details() {
get_bacs_account_details_html(假);
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 测试并启动。
- 然后你可以在页面的任何 Wordpress 编辑器中使用它,post 或自定义 post:
[bacs_account_details]
- 或者在PHP代码中:
echo do_shortcode('[bacs_account_details]');
我有一个很简单的想法,但我不知道如何在 WooCommerce 中实现。
在我的商店中,我启用了一些付款选项,也可以通过银行转帐付款。但是当客户选择银行转账时,他会看到进行转账所需的数据。但在那之后,没有选项可以在感谢页面上显示该数据,每个人都在寻找该数据。
有一种简单的方法可以再次显示该数据吗?
在感谢页面上使用操作,在您的 child functions.php 或使用代码片段插件
add_action('woocommerce_thankyou', 'customThankYouFunction');
并在你的function
中写下你的逻辑
function customThankYouFunction ($order_id) {
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method = $order_data['payment_method'];
}
您现在可以处理订单了
引用
Bacs 帐户详细信息存储在 wp_options
table 中,就像大多数 Wordpress 和 Woocommerce 设置一样。
可以使用访问它们(它给出了不同银行账户的多维数组,你可以设置很多):
$bacs_accounts_info = get_option( 'woocommerce_bacs_accounts');
通常,此详细信息默认显示在 woocommerce 谢谢页面和一些客户电子邮件通知中……
为了显示格式化的银行账户信息,我构建了这个自定义函数:
// Utility function, to display BACS accounts details
function get_bacs_account_details_html( $echo = true, $type = 'list' ) {
ob_start();
$gateway = new WC_Gateway_BACS();
$country = WC()->countries->get_base_country();
$locale = $gateway->get_country_locale();
$bacs_info = get_option( 'woocommerce_bacs_accounts');
// Get sortcode label in the $locale array and use appropriate one
$sort_code_label = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
if( $type == 'list' ) :
?>
<div class="woocommerce-bacs-bank-details">
<h2 class="wc-bacs-bank-details-heading"><?php _e('Our bank details'); ?></h2>
<?php
$i = -1;
if ( $bacs_info ) : foreach ( $bacs_info as $account ) :
$i++;
$account_name = esc_attr( wp_unslash( $account['account_name'] ) );
$bank_name = esc_attr( wp_unslash( $account['bank_name'] ) );
$account_number = esc_attr( $account['account_number'] );
$sort_code = esc_attr( $account['sort_code'] );
$iban_code = esc_attr( $account['iban'] );
$bic_code = esc_attr( $account['bic'] );
?>
<h3 class="wc-bacs-bank-details-account-name"><?php echo $account_name; ?>:</h3>
<ul class="wc-bacs-bank-details order_details bacs_details">
<li class="bank_name"><?php _e('Bank'); ?>: <strong><?php echo $bank_name; ?></strong></li>
<li class="account_number"><?php _e('Account number'); ?>: <strong><?php echo $account_number; ?></strong></li>
<li class="sort_code"><?php echo $sort_code_label; ?>: <strong><?php echo $sort_code; ?></strong></li>
<li class="iban"><?php _e('IBAN'); ?>: <strong><?php echo $iban_code; ?></strong></li>
<li class="bic"><?php _e('BIC'); ?>: <strong><?php echo $bic_code; ?></strong></li>
</ul>
<?php endforeach; endif; ?>
</div>
<?php
else :
?>
<h2><?php _e( 'Account details', 'woocommerce' ); ?>:</h2>
<table class="widefat wc_input_table" cellspacing="0">
<thead>
<tr>
<th><?php _e( 'Account name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank name', 'woocommerce' ); ?></th>
<th><?php echo $sort_code_label; ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody class="accounts">
<?php
$i = -1;
if ( $bacs_info ) {
foreach ( $bacs_info as $account ) {
$i++;
echo '<tr class="account">
<td>' . esc_attr( wp_unslash( $account['account_name'] ) ) . '</td>
<td>' . esc_attr( $account['account_number'] ) . '</td>
<td>' . esc_attr( wp_unslash( $account['bank_name'] ) ) . '</td>
<td>' . esc_attr( $account['sort_code'] ) . '</td>
<td>' . esc_attr( $account['iban'] ) . '</td>
<td>' . esc_attr( $account['bic'] ) . '</td>
</tr>';
}
}
?>
</tbody>
</table>
<?php
endif;
$output = ob_get_clean();
if ( $echo )
echo $output;
else
return $output;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。测试和工作。
可能的用法:
1) 在任何模板或 php 代码中 您将仅用于显示此帐户详细信息:
get_bacs_account_details_html();
2) 作为挂钩函数(您将在其中设置所需的操作挂钩)。
下面是一个示例用法,它将在我的帐户订单视图中显示此银行帐户详细信息,用于将 BACS 作为支付网关和“暂停”状态的订单:
add_action( 'woocommerce_view_order', 'display_bacs_account_details_on_view_order', 5, 1 );
function display_bacs_account_details_on_view_order( $order_id ){
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
if( $order->get_payment_method() === 'bacs' && $order->get_status() === 'on-hold' ){
get_bacs_account_details_html();
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效。
作为简码
[bacs_account_details]
:add_shortcode('bacs_account_details','shortcode_bacs_account_details'); 函数 shortcode_bacs_account_details() { get_bacs_account_details_html(假); }
代码进入您的活动子主题(或活动主题)的 function.php 文件。 测试并启动。
- 然后你可以在页面的任何 Wordpress 编辑器中使用它,post 或自定义 post:
[bacs_account_details]
- 或者在PHP代码中:
echo do_shortcode('[bacs_account_details]');