Merge pull request #6814 from bryceadams/patch-6026

#6026 - Introduction of Sort Code 'locale' for BACS
This commit is contained in:
Mike Jolley 2014-11-26 16:23:40 +00:00
commit 5f77ee752e
2 changed files with 100 additions and 4 deletions

View File

@ -975,4 +975,4 @@ class WC_Countries {
// Return
return $address_fields;
}
}
}

View File

@ -17,10 +17,14 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
class WC_Gateway_BACS extends WC_Payment_Gateway {
/** @var array Array of locales */
public $locale;
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'bacs';
$this->icon = apply_filters('woocommerce_bacs_icon', '');
$this->has_fields = false;
@ -57,12 +61,14 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
}
/**
* Initialise Gateway Settings Form Fields
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
@ -95,13 +101,22 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'type' => 'account_details'
),
);
}
/**
* generate_account_details_html function.
*/
public function generate_account_details_html() {
ob_start();
$country = WC()->countries->get_base_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' );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Account Details', 'woocommerce' ); ?>:</th>
@ -113,7 +128,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
<th><?php _e( 'Account Name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account Number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank Name', 'woocommerce' ); ?></th>
<th><?php _e( 'Sort Code', 'woocommerce' ); ?></th>
<th><?php echo $sortcode; ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr>
@ -168,12 +183,14 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
</tr>
<?php
return ob_get_clean();
}
/**
* Save account details table
*/
public function save_account_details() {
$accounts = array();
if ( isset( $_POST['bacs_account_name'] ) ) {
@ -202,16 +219,19 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
}
update_option( 'woocommerce_bacs_accounts', $accounts );
}
/**
* Output for the order received page.
*/
public function thankyou_page( $order_id ) {
if ( $this->instructions ) {
echo wpautop( wptexturize( wp_kses_post( $this->instructions ) ) );
}
$this->bank_details( $order_id );
}
/**
@ -224,28 +244,42 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
* @return void
*/
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( ! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status( 'on-hold' ) ) {
if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
}
$this->bank_details( $order->id );
}
}
/**
* Get bank details and place into a list format
*/
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' );
echo '<h2>' . __( 'Our Bank Details', 'woocommerce' ) . '</h2>' . PHP_EOL;
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details );
if ( ! empty( $bacs_accounts ) ) {
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
if ( $bacs_account->account_name || $bacs_account->bank_name ) {
@ -261,7 +295,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'value' => $bacs_account->account_number
),
'sort_code' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
'label' => $sortcode,
'value' => $bacs_account->sort_code
),
'iban' => array(
@ -283,6 +317,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
echo '</ul>';
}
}
}
/**
@ -309,5 +344,66 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
}
/**
* Get country locale if localized
*
* @return array
*/
public function get_country_locale() {
if ( ! $this->locale ) {
// Locale information to be used - only those that are not 'Sort Code'
$this->locale = apply_filters( 'woocommerce_get_bacs_locale', array(
'AU' => array(
'sortcode' => array(
'label' => __( 'BSB', 'woocommerce' ),
),
),
'CA' => array(
'sortcode' => array(
'label' => __( 'Bank Transit Number', 'woocommerce' ),
),
),
'IN' => array(
'sortcode' => array(
'label' => __( 'IFSC', 'woocommerce' ),
),
),
'IT' => array(
'sortcode' => array(
'label' => __( 'Branch Sort', 'woocommerce' ),
),
),
'NZ' => array(
'sortcode' => array(
'label' => __( 'Bank Code', 'woocommerce' ),
),
),
'SE' => array(
'sortcode' => array(
'label' => __( 'Bank Code', 'woocommerce' ),
),
),
'US' => array(
'sortcode' => array(
'label' => __( 'Routing Number', 'woocommerce' ),
),
),
'ZA' => array(
'sortcode' => array(
'label' => __( 'Branch Code', 'woocommerce' ),
),
),
) );
}
return $this->locale;
}
}