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