@@ -971,12 +971,16 @@ public function update_shipping_method( $shipping_methods ) {
971
971
972
972
/**
973
973
* Normalizes billing and shipping state fields.
974
+ *
975
+ * @param array $data Address data.
976
+ *
977
+ * @return array Normalized address data.
974
978
*/
975
- public function normalize_state () {
976
- $ billing_country = ! empty ( $ _POST [ ' billing_country ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_country ' ] ) ) : '' ;
977
- $ shipping_country = ! empty ( $ _POST [ ' shipping_country ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_country ' ] ) ) : '' ;
978
- $ billing_state = ! empty ( $ _POST [ ' billing_state ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_state ' ] ) ) : '' ;
979
- $ shipping_state = ! empty ( $ _POST [ ' shipping_state ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_state ' ] ) ) : '' ;
979
+ public function normalize_state ( $ data ) {
980
+ $ billing_country = ! empty ( $ data [ ' billing_address ' ][ ' country ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' country ' ] ) ) : '' ;
981
+ $ shipping_country = ! empty ( $ data [ ' shipping_address ' ][ ' country ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' country ' ] ) ) : '' ;
982
+ $ billing_state = ! empty ( $ data [ ' billing_address ' ][ ' state ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' state ' ] ) ) : '' ;
983
+ $ shipping_state = ! empty ( $ data [ ' shipping_address ' ][ ' state ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' state ' ] ) ) : '' ;
980
984
981
985
// Due to a bug in Apple Pay, the "Region" part of a Hong Kong address is delivered in
982
986
// `shipping_postcode`, so we need some special case handling for that. According to
@@ -1000,7 +1004,7 @@ public function normalize_state() {
1000
1004
include_once WC_STRIPE_PLUGIN_PATH . '/includes/constants/class-wc-stripe-hong-kong-states.php ' ;
1001
1005
1002
1006
if ( ! WC_Stripe_Hong_Kong_States::is_valid_state ( strtolower ( $ billing_state ) ) ) {
1003
- $ billing_postcode = ! empty ( $ _POST [ ' billing_postcode ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_postcode ' ] ) ) : '' ;
1007
+ $ billing_postcode = ! empty ( $ data [ ' billing_address ' ][ ' postcode ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' postcode ' ] ) ) : '' ;
1004
1008
if ( WC_Stripe_Hong_Kong_States::is_valid_state ( strtolower ( $ billing_postcode ) ) ) {
1005
1009
$ billing_state = $ billing_postcode ;
1006
1010
}
@@ -1010,7 +1014,7 @@ public function normalize_state() {
1010
1014
include_once WC_STRIPE_PLUGIN_PATH . '/includes/constants/class-wc-stripe-hong-kong-states.php ' ;
1011
1015
1012
1016
if ( ! WC_Stripe_Hong_Kong_States::is_valid_state ( strtolower ( $ shipping_state ) ) ) {
1013
- $ shipping_postcode = ! empty ( $ _POST [ ' shipping_postcode ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_postcode ' ] ) ) : '' ;
1017
+ $ shipping_postcode = ! empty ( $ data [ ' shipping_address ' ][ ' postcode ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' postcode ' ] ) ) : '' ;
1014
1018
if ( WC_Stripe_Hong_Kong_States::is_valid_state ( strtolower ( $ shipping_postcode ) ) ) {
1015
1019
$ shipping_state = $ shipping_postcode ;
1016
1020
}
@@ -1019,12 +1023,14 @@ public function normalize_state() {
1019
1023
1020
1024
// Finally we normalize the state value we want to process.
1021
1025
if ( $ billing_state && $ billing_country ) {
1022
- $ _POST [ ' billing_state ' ] = $ this ->get_normalized_state ( $ billing_state , $ billing_country );
1026
+ $ data [ ' billing_address ' ][ ' state ' ] = $ this ->get_normalized_state ( $ billing_state , $ billing_country );
1023
1027
}
1024
1028
1025
1029
if ( $ shipping_state && $ shipping_country ) {
1026
- $ _POST [ ' shipping_state ' ] = $ this ->get_normalized_state ( $ shipping_state , $ shipping_country );
1030
+ $ data [ ' shipping_address ' ][ ' state ' ] = $ this ->get_normalized_state ( $ shipping_state , $ shipping_country );
1027
1031
}
1032
+
1033
+ return $ data ;
1028
1034
}
1029
1035
1030
1036
/**
@@ -1174,34 +1180,40 @@ public function validate_state() {
1174
1180
1175
1181
/**
1176
1182
* Performs special mapping for address fields for specific contexts.
1183
+ *
1184
+ * @param array $data Address data.
1185
+ *
1186
+ * @return array Address data.
1177
1187
*/
1178
- public function fix_address_fields_mapping () {
1179
- $ billing_country = ! empty ( $ _POST [ ' billing_country ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_country ' ] ) ) : '' ;
1180
- $ shipping_country = ! empty ( $ _POST [ ' shipping_country ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_country ' ] ) ) : '' ;
1188
+ public function fix_address_fields_mapping ( $ data ) {
1189
+ $ billing_country = ! empty ( $ data [ ' billing_address ' ][ ' country ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' country ' ] ) ) : '' ;
1190
+ $ shipping_country = ! empty ( $ data [ ' shipping_address ' ][ ' country ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' country ' ] ) ) : '' ;
1181
1191
1182
1192
// For UAE, Google Pay stores the emirate in "region", which gets mapped to the "state" field,
1183
1193
// but WooCommerce expects it in the "city" field.
1184
1194
if ( 'AE ' === $ billing_country ) {
1185
- $ billing_state = ! empty ( $ _POST [ ' billing_state ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_state ' ] ) ) : '' ;
1186
- $ billing_city = ! empty ( $ _POST [ ' billing_city ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' billing_city ' ] ) ) : '' ;
1195
+ $ billing_state = ! empty ( $ data [ ' billing_address ' ][ ' state ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' state ' ] ) ) : '' ;
1196
+ $ billing_city = ! empty ( $ data [ ' billing_address ' ][ ' city ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' billing_address ' ][ ' city ' ] ) ) : '' ;
1187
1197
1188
1198
// Move the state (emirate) to the city field.
1189
1199
if ( empty ( $ billing_city ) && ! empty ( $ billing_state ) ) {
1190
- $ _POST [ ' billing_city ' ] = $ billing_state ;
1191
- $ _POST [ ' billing_state ' ] = '' ;
1200
+ $ data [ ' billing_address ' ][ ' city ' ] = $ billing_state ;
1201
+ $ data [ ' billing_address ' ][ ' state ' ] = '' ;
1192
1202
}
1193
1203
}
1194
1204
1195
1205
if ( 'AE ' === $ shipping_country ) {
1196
- $ shipping_state = ! empty ( $ _POST [ ' shipping_state ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_state ' ] ) ) : '' ;
1197
- $ shipping_city = ! empty ( $ _POST [ ' shipping_city ' ] ) ? wc_clean ( wp_unslash ( $ _POST [ ' shipping_city ' ] ) ) : '' ;
1206
+ $ shipping_state = ! empty ( $ data [ ' shipping_address ' ][ ' state ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' state ' ] ) ) : '' ;
1207
+ $ shipping_city = ! empty ( $ data [ ' shipping_address ' ][ ' city ' ] ) ? wc_clean ( wp_unslash ( $ data [ ' shipping_address ' ][ ' city ' ] ) ) : '' ;
1198
1208
1199
1209
// Move the state (emirate) to the city field.
1200
1210
if ( empty ( $ shipping_city ) && ! empty ( $ shipping_state ) ) {
1201
- $ _POST [ ' shipping_city ' ] = $ shipping_state ;
1202
- $ _POST [ ' shipping_state ' ] = '' ;
1211
+ $ data [ ' shipping_address ' ][ ' city ' ] = $ shipping_state ;
1212
+ $ data [ ' shipping_address ' ][ ' state ' ] = '' ;
1203
1213
}
1204
1214
}
1215
+
1216
+ return $ data ;
1205
1217
}
1206
1218
1207
1219
/**
0 commit comments