/**
  * Loads Cart User Billing Details Template
  * 
  * Handles to load user billing details
  * template
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  */
 function wps_deals_cart_user_billing_details()
 {
     global $current_user, $wps_deals_options;
     //check billing is enable from settings page
     if (isset($wps_deals_options['enable_billing']) && !empty($wps_deals_options['enable_billing'])) {
         $prefix = WPS_DEALS_META_PREFIX;
         //get user billing data saved
         $userbillingdata = get_user_meta($current_user->ID, $prefix . 'billing_details', true);
         //get user country from saved
         $usercountry = isset($userbillingdata['country']) ? $userbillingdata['country'] : '';
         //get user company name
         $usercompany = isset($userbillingdata['company']) ? $userbillingdata['company'] : '';
         //get user address1
         $useraddress1 = isset($userbillingdata['address1']) ? $userbillingdata['address1'] : '';
         //get user address2
         $useraddress2 = isset($userbillingdata['address2']) ? $userbillingdata['address2'] : '';
         //get user city or town
         $usercity = isset($userbillingdata['city']) ? $userbillingdata['city'] : '';
         //get user state or county
         $userstate = isset($userbillingdata['state']) ? $userbillingdata['state'] : '';
         //get user post code
         $userpostcode = isset($userbillingdata['postcode']) ? $userbillingdata['postcode'] : '';
         //get user phone
         $userphone = isset($userbillingdata['phone']) ? $userbillingdata['phone'] : '';
         //get statelist from country
         $statesfrom = wps_deals_get_states_from_country($usercountry);
         $states = !empty($statesfrom) ? $statesfrom : '';
         //data pased to template
         $billingargs = array('countries' => wps_deals_get_country_list(), 'usercountry' => $usercountry, 'usercompany' => $usercompany, 'useraddress1' => $useraddress1, 'useraddress2' => $useraddress2, 'usercity' => $usercity, 'userstate' => $userstate, 'userpostcode' => $userpostcode, 'userphone' => $userphone, 'statelist' => $states);
         //billing details template
         wps_deals_get_template('checkout/footer/billing-details.php', $billingargs);
     }
     //end if to check enable billing or not
 }
 /**
  * Call to return state list from Country Code
  * 
  * Handles to return state list from country code
  * 
  * @package Social Deals Engine
  * @since 1.0.0 
  **/
 public function wps_deals_state_list_from_country()
 {
     $country = isset($_POST['country']) && !empty($_POST['country']) ? $_POST['country'] : '';
     $stateid = isset($_POST['stateid']) ? $_POST['stateid'] : '';
     //$stateclass = isset( $_POST['stateclass'] ) ? $_POST['stateclass'] : '';
     $statename = isset($_POST['statename']) ? $_POST['statename'] : '';
     //$stateplaceholder	= isset( $_POST['stateplaceholder'] ) ? $_POST['stateplaceholder'] : '';
     //get states from country
     $states = wps_deals_get_states_from_country($country);
     //check states not empty
     if (!empty($states) && is_array($states)) {
         $statefield = '<select name="' . $statename . '" id="' . $stateid . '" class="deals-cart-select wps-deals-required billing-country wps-deals-state-combo">';
         $statefield .= '<option value="">' . __('Select State / County&hellip;', 'wpsdeals') . '</option>';
         foreach ($states as $statekey => $state) {
             $statefield .= '<option value="' . $statekey . '">' . $state . '</option>';
         }
         $statefield .= '</select>';
     } else {
         $statefield = '<input type="text" name="' . $statename . '" id="' . $stateid . '" value="" class="wps-deals-cart-text wps-deals-required wps-deals-state-combo" placeholder="' . __('State / County', 'wpsdeals') . '"/>';
     }
     echo $statefield;
     exit;
 }
/**
 * Get State From State Key 
 * 
 * Handles to return state value from state key
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 **/
function wps_deals_get_state_name($state, $country)
{
    if (empty($state) || empty($country)) {
        return '';
    }
    $resultstate = '';
    $stateslist = wps_deals_get_states_from_country($country);
    //check is there any inbuilt states available for this country or not
    if (!empty($stateslist) && is_array($stateslist)) {
        $resultstate = isset($stateslist[$state]) ? $stateslist[$state] : $state;
    } else {
        //else return which is passed
        $resultstate = $state;
    }
    return $resultstate;
}