Move locale to new method in BACS gateway

This commit is contained in:
Bryce 2014-11-24 21:26:33 +07:00
parent 7abd1358fc
commit 3fd7997413
2 changed files with 104 additions and 54 deletions

View File

@ -606,10 +606,7 @@ class WC_Countries {
),
'state' => array(
'label' => __( 'State', 'woocommerce' ),
),
'sortcode' => array(
'label' => __( 'BSB', 'woocommerce' ),
),
)
),
'BD' => array(
'postcode' => array(
@ -646,10 +643,7 @@ class WC_Countries {
'CA' => array(
'state' => array(
'label' => __( 'Province', 'woocommerce' ),
),
'sortcode' => array(
'label' => __( 'Bank Transit Number', 'woocommerce' ),
),
)
),
'CH' => array(
'postcode_before_city' => true,
@ -732,16 +726,6 @@ class WC_Countries {
'label' => __( 'Province', 'woocommerce' ),
)
),
'IE' => array(
'sortcode' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
),
),
'IN' => array(
'sortcode' => array(
'label' => __( 'IFSC', 'woocommerce' ),
),
),
'IS' => array(
'postcode_before_city' => true,
'state' => array(
@ -759,10 +743,7 @@ class WC_Countries {
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
'sortcode' => array(
'label' => __( 'Branch Sort', 'woocommerce' ),
),
)
),
'JP' => array(
'state' => array(
@ -784,10 +765,7 @@ class WC_Countries {
'NZ' => array(
'state' => array(
'required' => false
),
'sortcode' => array(
'label' => __( 'Bank Code', 'woocommerce' ),
),
)
),
'NO' => array(
'postcode_before_city' => true,
@ -850,10 +828,7 @@ class WC_Countries {
'postcode_before_city' => true,
'state' => array(
'required' => false
),
'sortcode' => array(
'label' => __( 'Bank Code', 'woocommerce' ),
),
)
),
'TR' => array(
'postcode_before_city' => true,
@ -867,10 +842,7 @@ class WC_Countries {
),
'state' => array(
'label' => __( 'State', 'woocommerce' ),
),
'sortcode' => array(
'label' => __( 'Routing Number', 'woocommerce' ),
),
)
),
'GB' => array(
'postcode' => array(
@ -879,10 +851,7 @@ class WC_Countries {
'state' => array(
'label' => __( 'County', 'woocommerce' ),
'required' => false
),
'sortcode' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
),
)
),
'VN' => array(
'state' => array(
@ -906,10 +875,7 @@ class WC_Countries {
'ZA' => array(
'state' => array(
'label' => __( 'Province', 'woocommerce' ),
),
'sortcode' => array(
'label' => __( 'Branch Code', 'woocommerce' ),
),
)
),
'ZW' => array(
'postcode' => array(
@ -926,9 +892,8 @@ class WC_Countries {
$this->locale['default'] = apply_filters('woocommerce_get_country_locale_default', $this->get_default_address_fields() );
// Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout
if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
if ( ! isset( $this->locale[ $this->get_base_country() ] ) )
$this->locale[ $this->get_base_country() ] = $this->locale['default'];
}
$this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
$this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
@ -1010,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,19 +101,21 @@ 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 = WC()->countries->get_country_locale();
$locale = $this->get_country_locale();
$sortcode_label = $locale[$country]['sortcode']['label'];
$sortcode = $sortcode_label ? $sortcode_label : __( 'Sort Code', 'woocommerce' );
// 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">
@ -175,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'] ) ) {
@ -209,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 );
}
/**
@ -231,18 +244,21 @@ 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;
}
@ -252,13 +268,10 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
// Get the order country and country $locale
$country = $order->billing_country;
$locale = WC()->countries->get_country_locale();
$locale = $this->get_country_locale();
// Get sortcode label in the $locale array
$sortcode_label = $locale[$country]['sortcode']['label'];
// If a sortcode label exists uses it, if not use Sort Code
$sortcode = $sortcode_label ? $sortcode_label : __( 'Sort Code', 'woocommerce' );
// 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;
@ -304,6 +317,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
echo '</ul>';
}
}
}
/**
@ -330,5 +344,76 @@ 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
$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' ),
),
),
'GB' => array(
'sortcode' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
),
),
'IE' => array(
'sortcode' => array(
'label' => __( 'Sort Code', '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;
}
}