From 6dad8fdc59e194c1571ecedf8d5149cd449b8a46 Mon Sep 17 00:00:00 2001 From: Bryce Date: Fri, 21 Nov 2014 16:10:12 +0700 Subject: [PATCH 1/4] #6026 - Introduction of Sort Code 'locale' for BACS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the admin, it will use the store’s base country to determine the term for ‘Sort Code’. In the front-end, it will use the customer’s billing country to determine the term for ‘Sort Code’. In all cases, if a locale does not have a sortcode label set, it will use ‘Sort Code’. **Locales have been added for:** * AU * CA * IE * IN * IT * NZ * SE * US * GB * ZA But may need adjusting based on user feedback. --- includes/class-wc-countries.php | 53 +++++++++++++++---- .../gateways/bacs/class-wc-gateway-bacs.php | 27 ++++++++-- 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index b956116fb85..68258a5b4d5 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -606,7 +606,10 @@ class WC_Countries { ), 'state' => array( 'label' => __( 'State', 'woocommerce' ), - ) + ), + 'sortcode' => array( + 'label' => __( 'BSB', 'woocommerce' ), + ), ), 'BD' => array( 'postcode' => array( @@ -643,7 +646,10 @@ class WC_Countries { 'CA' => array( 'state' => array( 'label' => __( 'Province', 'woocommerce' ), - ) + ), + 'sortcode' => array( + 'label' => __( 'Bank Transit Number', 'woocommerce' ), + ), ), 'CH' => array( 'postcode_before_city' => true, @@ -725,6 +731,16 @@ class WC_Countries { 'state' => array( 'label' => __( 'Province', 'woocommerce' ), ) + ), + 'IE' => array( + 'sortcode' => array( + 'label' => __( 'Sort Code', 'woocommerce' ), + ), + ), + 'IN' => array( + 'sortcode' => array( + 'label' => __( 'IFSC', 'woocommerce' ), + ), ), 'IS' => array( 'postcode_before_city' => true, @@ -743,7 +759,10 @@ class WC_Countries { 'state' => array( 'required' => true, 'label' => __( 'Province', 'woocommerce' ), - ) + ), + 'sortcode' => array( + 'label' => __( 'Branch Sort', 'woocommerce' ), + ), ), 'JP' => array( 'state' => array( @@ -765,7 +784,10 @@ class WC_Countries { 'NZ' => array( 'state' => array( 'required' => false - ) + ), + 'sortcode' => array( + 'label' => __( 'Bank Code', 'woocommerce' ), + ), ), 'NO' => array( 'postcode_before_city' => true, @@ -828,7 +850,10 @@ class WC_Countries { 'postcode_before_city' => true, 'state' => array( 'required' => false - ) + ), + 'sortcode' => array( + 'label' => __( 'Bank Code', 'woocommerce' ), + ), ), 'TR' => array( 'postcode_before_city' => true, @@ -842,7 +867,10 @@ class WC_Countries { ), 'state' => array( 'label' => __( 'State', 'woocommerce' ), - ) + ), + 'sortcode' => array( + 'label' => __( 'Routing Number', 'woocommerce' ), + ), ), 'GB' => array( 'postcode' => array( @@ -851,7 +879,10 @@ class WC_Countries { 'state' => array( 'label' => __( 'County', 'woocommerce' ), 'required' => false - ) + ), + 'sortcode' => array( + 'label' => __( 'Sort Code', 'woocommerce' ), + ), ), 'VN' => array( 'state' => array( @@ -875,7 +906,10 @@ class WC_Countries { 'ZA' => array( 'state' => array( 'label' => __( 'Province', 'woocommerce' ), - ) + ), + 'sortcode' => array( + 'label' => __( 'Branch Code', 'woocommerce' ), + ), ), 'ZW' => array( 'postcode' => array( @@ -892,8 +926,9 @@ 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() ] ); diff --git a/includes/gateways/bacs/class-wc-gateway-bacs.php b/includes/gateways/bacs/class-wc-gateway-bacs.php index 3922a74f70a..74e1a39f944 100644 --- a/includes/gateways/bacs/class-wc-gateway-bacs.php +++ b/includes/gateways/bacs/class-wc-gateway-bacs.php @@ -102,6 +102,13 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { */ public function generate_account_details_html() { ob_start(); + + $country = WC()->countries->get_base_country(); + $locale = WC()->countries->get_country_locale(); + + $sortcode_label = $locale[$country]['sortcode']['label']; + $sortcode = $sortcode_label ? $sortcode_label : __( 'Sort Code', 'woocommerce' ); + ?> : @@ -113,7 +120,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { - + @@ -240,12 +247,26 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { 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 = WC()->countries->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' ); + echo '

' . __( 'Our Bank Details', 'woocommerce' ) . '

' . 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 +282,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( @@ -310,4 +331,4 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { 'redirect' => $this->get_return_url( $order ) ); } -} +} \ No newline at end of file From 7abd1358fc3eb0e2ffb37f35df05b19d50f26c67 Mon Sep 17 00:00:00 2001 From: Bryce Date: Fri, 21 Nov 2014 16:13:03 +0700 Subject: [PATCH 2/4] Fix whitespace --- includes/class-wc-countries.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 68258a5b4d5..99e62534e19 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -732,16 +732,16 @@ class WC_Countries { 'label' => __( 'Province', 'woocommerce' ), ) ), - 'IE' => array( + 'IE' => array( 'sortcode' => array( 'label' => __( 'Sort Code', 'woocommerce' ), ), - ), - 'IN' => array( + ), + 'IN' => array( 'sortcode' => array( 'label' => __( 'IFSC', 'woocommerce' ), ), - ), + ), 'IS' => array( 'postcode_before_city' => true, 'state' => array( From 3fd799741317e5116c7a237b6128f22a9f24c4fb Mon Sep 17 00:00:00 2001 From: Bryce Date: Mon, 24 Nov 2014 21:26:33 +0700 Subject: [PATCH 3/4] Move locale to new method in BACS gateway --- includes/class-wc-countries.php | 55 ++-------- .../gateways/bacs/class-wc-gateway-bacs.php | 103 ++++++++++++++++-- 2 files changed, 104 insertions(+), 54 deletions(-) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 99e62534e19..d9ec0da0053 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -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; } -} +} \ No newline at end of file diff --git a/includes/gateways/bacs/class-wc-gateway-bacs.php b/includes/gateways/bacs/class-wc-gateway-bacs.php index 74e1a39f944..bbfb4fd6240 100644 --- a/includes/gateways/bacs/class-wc-gateway-bacs.php +++ b/includes/gateways/bacs/class-wc-gateway-bacs.php @@ -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' ); ?> @@ -175,12 +183,14 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { 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 '

' . __( 'Our Bank Details', 'woocommerce' ) . '

' . PHP_EOL; @@ -304,6 +317,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { echo ''; } } + } /** @@ -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; + } } \ No newline at end of file From 8f89ef9c0bc374d68dce54b589cb901d451f0055 Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 26 Nov 2014 23:03:48 +0700 Subject: [PATCH 4/4] Remove locales with 'Sort Code' Wrong swamp --- includes/gateways/bacs/class-wc-gateway-bacs.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/includes/gateways/bacs/class-wc-gateway-bacs.php b/includes/gateways/bacs/class-wc-gateway-bacs.php index bbfb4fd6240..cabe19e40d9 100644 --- a/includes/gateways/bacs/class-wc-gateway-bacs.php +++ b/includes/gateways/bacs/class-wc-gateway-bacs.php @@ -357,7 +357,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { if ( ! $this->locale ) { - // Locale information to be used + // 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( @@ -369,16 +369,6 @@ class WC_Gateway_BACS extends WC_Payment_Gateway { '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' ),