Skip to content

Commit

Permalink
Fix: address fields not checking which fields are optional, #681
Browse files Browse the repository at this point in the history
  • Loading branch information
mahbubme committed Jul 2, 2019
1 parent b952ced commit fb8ba96
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
9 changes: 6 additions & 3 deletions assets/js/billing-address.js
Expand Up @@ -47,9 +47,12 @@ jQuery(function($){
var city = $("#wpuf_biiling_city");
var zip = $("#wpuf_biiling_zip_code");

if ( ( country.val() === '' || state.val() === '' ) || ( add_1.hasClass('bill_required') && add_1.val() === "" ) ||
( add_1.hasClass('bill_required') && add_1.val() === "" ) || ( add_2.hasClass('bill_required') && add_2.val() === "" ) ||
( city.hasClass('bill_required') && city.val() === "" ) || ( zip.hasClass('bill_required') && zip.val() === "" ) ) {
if ( ( country.val() === '' || state.val() === '' ) ||
( add_1.hasClass('bill_required') && add_1.val() === "" ) ||
( add_2.hasClass('bill_required') && add_2.val() === "" ) ||
( city.hasClass('bill_required') && city.val() === "" ) ||
( zip.hasClass('bill_required') && zip.val() === "" ) )
{
alert( ajax_object.fill_notice );
e.preventDefault();
}
Expand Down
45 changes: 21 additions & 24 deletions includes/class-billing-address.php
Expand Up @@ -47,6 +47,9 @@ public static function wpuf_ajax_address_form() {
$show_city = wpuf_get_option( 'city', 'wpuf_address_options', false );
$show_zip = wpuf_get_option( 'zip', 'wpuf_address_options', false );

$required_class = 'bill_required';
$req_div = '<span class="required">*</span>';

$country_req = ''; $country_hide = ''; $state_req = ''; $state_hide = ''; $add1_req = ''; $add1_hide = '';
$add2_req = ''; $add2_hide = ''; $city_req = ''; $city_hide = ''; $zip_req = ''; $zip_hide = ''; $required = '';

Expand All @@ -56,8 +59,7 @@ public static function wpuf_ajax_address_form() {

switch ( $show_country ) {
case 'required':
$country_req = '<span class="required">*</span>';
$required = 'bill_required';
$country_required = true;
break;
case 'hidden':
$country_hide = 'display: none;';
Expand All @@ -66,8 +68,7 @@ public static function wpuf_ajax_address_form() {
}
switch ( $show_state ) {
case 'required':
$state_req = '<span class="required">*</span>';
$required = 'bill_required';
$state_required = true;
break;
case 'hidden':
$state_hide = 'display: none;';
Expand All @@ -76,8 +77,7 @@ public static function wpuf_ajax_address_form() {
}
switch ( $show_add1 ) {
case 'required':
$add1_req = '<span class="required">*</span>';
$required = 'bill_required';
$address1_required = true;
break;
case 'hidden':
$add1_hide = 'display: none;';
Expand All @@ -86,8 +86,7 @@ public static function wpuf_ajax_address_form() {
}
switch ( $show_add2 ) {
case 'required':
$add2_req = '<span class="required">*</span>';
$required = 'bill_required';
$address2_required = true;
break;
case 'hidden':
$add2_hide = 'display: none;';
Expand All @@ -96,8 +95,7 @@ public static function wpuf_ajax_address_form() {
}
switch ( $show_city ) {
case 'required':
$city_req = '<span class="required">*</span>';
$required = 'bill_required';
$city_required = true;
break;
case 'hidden':
$city_hide = 'display: none;';
Expand All @@ -106,8 +104,7 @@ public static function wpuf_ajax_address_form() {
}
switch ( $show_zip ) {
case 'required':
$zip_req = '<span class="required">*</span>';
$required = 'bill_required';
$zip_required = true;
break;
case 'hidden':
$zip_hide = 'display: none;';
Expand All @@ -121,8 +118,8 @@ public static function wpuf_ajax_address_form() {
<form class="wpuf-form form-label-above" id="wpuf-ajax-address-form" action="" method="post">
<table id="wpuf-address-country-state" class="wp-list-table widefat">
<tr>
<td class="<?php echo $required; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $country_hide; ?>">
<label><?php _e( "Country", "wp-user-frontend" ); ?><?php echo $country_req ?></label>
<td class="<?php echo isset( $country_required ) ? $required_class : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $country_hide; ?>">
<label><?php _e( "Country", "wp-user-frontend" ); ?><?php echo isset( $country_required ) ? $req_div : null; ?></label>
<br>
<?php
if (function_exists('wpuf_get_tax_rates')) {
Expand All @@ -148,8 +145,8 @@ public static function wpuf_ajax_address_form() {
));
?>
</td>
<td class="<?php echo $required; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $state_hide;?>">
<label><?php _e( "State/Province/Region", "wp-user-frontend" ); ?><?php echo $state_req; ?></label>
<td class="<?php echo isset( $state_required ) ? $required_class : null; ?>" style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $state_hide;?>">
<label><?php _e( "State/Province/Region", "wp-user-frontend" ); ?><?php echo isset( $state_required ) ? $req_div : null; ?></label>
<br>
<?php
$states = $cs->getStates($selected['country']);
Expand All @@ -168,32 +165,32 @@ public static function wpuf_ajax_address_form() {
?>
</td>
<td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $add1_hide;?>">
<div class="wpuf-label"><?php _e('Address Line 1 ', 'wp-user-frontend'); ?><?php echo $add1_req; ?></div>
<div class="wpuf-label"><?php _e('Address Line 1 ', 'wp-user-frontend'); ?><?php echo isset( $address1_required ) ? $req_div : null; ?></div>
<div class="wpuf-fields">
<input type="text" class="input <?php echo $required; ?>" name="wpuf_biiling_add_line_1"
<input type="text" class="input <?php echo isset( $address1_required ) ? $required_class : null; ?>" name="wpuf_biiling_add_line_1"
id="wpuf_biiling_add_line_1"
value="<?php echo $address_fields['add_line_1']; ?>"/>
</div>
</td>
<td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $add2_hide;?>">
<div class="wpuf-label"><?php _e('Address Line 2 ', 'wp-user-frontend'); ?><?php echo $add2_req; ?></div>
<div class="wpuf-label"><?php _e('Address Line 2 ', 'wp-user-frontend'); ?><?php echo isset( $address2_required ) ? $req_div : null; ?></div>
<div class="wpuf-fields">
<input type="text" class="input <?php echo $required; ?>" name="wpuf_biiling_add_line_2"
<input type="text" class="input <?php echo isset( $address2_required ) ? $required_class : null; ?>" name="wpuf_biiling_add_line_2"
id="wpuf_biiling_add_line_2"
value="<?php echo $address_fields['add_line_2']; ?>"/>
</div>
</td>
<td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $city_hide; ?>">
<div class="wpuf-label"><?php _e('City', 'wp-user-frontend'); ?><?php echo $city_req ?></div>
<div class="wpuf-label"><?php _e('City', 'wp-user-frontend'); ?><?php echo isset( $city_required ) ? $req_div : null; ?></div>
<div class="wpuf-fields">
<input type="text" class="input <?php echo $required; ?>" name="wpuf_biiling_city" id="wpuf_biiling_city"
<input type="text" class="input <?php echo isset( $city_required ) ? $required_class : null; ?>" name="wpuf_biiling_city" id="wpuf_biiling_city"
value="<?php echo $address_fields['city']; ?>"/>
</div>
</td>
<td style="display:inline-block;float:left;width:100%;margin:0px;padding:5px;<?php echo $zip_hide; ?>">
<div class="wpuf-label"><?php _e('Postal Code/ZIP', 'wp-user-frontend'); ?><?php echo $zip_req ?></div>
<div class="wpuf-label"><?php _e('Postal Code/ZIP', 'wp-user-frontend'); ?><?php echo isset( $zip_required ) ? $req_div : null; ?></div>
<div class="wpuf-fields">
<input type="text" class="input <?php echo $required; ?>" name="wpuf_biiling_zip_code" id="wpuf_biiling_zip_code"
<input type="text" class="input <?php echo isset( $zip_required ) ? $required_class : null; ?>" name="wpuf_biiling_zip_code" id="wpuf_biiling_zip_code"
value="<?php echo $address_fields['zip_code']; ?>"/>
</div>
</td>
Expand Down

0 comments on commit fb8ba96

Please sign in to comment.