/** * get a country list for checkout * * @param string|null $form_id * @param deprecated|null $ajax * @param string|null $selected_country * @param deprecated|null $selected_region * @param string|null $supplied_form_id * @param boolean $shippingfields * @return string */ function wpsc_country_list($form_id = null, $ajax = null, $selected_country = null, $selected_region = null, $supplied_form_id = null, $shippingfields = false) { global $wpdb; $output = ''; if ($form_id != null) { $html_form_id = "region_country_form_{$form_id}"; } else { $html_form_id = 'region_country_form'; } if ($shippingfields) { $js = ''; $title = 'shippingcountry'; $id = 'shippingcountry'; } else { $js = ''; $title = 'billingcountry'; $id = 'billingcountry'; } if (empty($supplied_form_id)) { $supplied_form_id = $id; } // if there is only one country to choose from we are going to set that as the shipping country, // later in the UI generation the same thing will happen to make the single country the current // selection $countries = WPSC_Countries::get_countries(false); if (count($countries) == 1) { reset($countries); $id_of_only_country_available = key($countries); $wpsc_country = new WPSC_Country($id_of_only_country_available); wpsc_update_customer_meta($id, $wpsc_country->get_isocode()); } $additional_attributes = 'data-wpsc-meta-key="' . $title . '" title="' . $title . '" ' . $js; $output .= "<div id='{$html_form_id}'>\n\r"; $output .= wpsc_get_country_dropdown(array('id' => $supplied_form_id, 'name' => "collected_data[{$form_id}][0]", 'class' => 'current_country wpsc-visitor-meta', 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce'))); $output .= "</div>\n\r"; return $output; }
function wpsc_shipping_country_list($shippingdetails = false) { global $wpsc_shipping_modules; $wpsc_checkout = new wpsc_checkout(); $wpsc_checkout->checkout_item = $shipping_country_checkout_item = $wpsc_checkout->get_checkout_item('shippingcountry'); $output = ''; if ($shipping_country_checkout_item && $shipping_country_checkout_item->active) { if (!$shippingdetails) { $output = "<input type='hidden' name='wpsc_ajax_action' value='update_location' />"; } $acceptable_countries = wpsc_get_acceptable_countries(); // if there is only one country to choose from we are going to set that as the shipping country, // later in the UI generation the same thing will happen to make the single country the current // selection $countries = WPSC_Countries::get_countries(false); if (count($countries) == 1) { reset($countries); $id_of_only_country_available = key($countries); $wpsc_country = new WPSC_Country($id_of_only_country_available); wpsc_update_customer_meta('shippingcountry', $wpsc_country->get_isocode()); } $selected_country = wpsc_get_customer_meta('shippingcountry'); $additional_attributes = 'data-wpsc-meta-key="shippingcountry" '; $output .= wpsc_get_country_dropdown(array('id' => 'current_country', 'name' => 'country', 'class' => 'current_country wpsc-visitor-meta', 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce'))); } $output .= wpsc_checkout_shipping_state_and_region(); $zipvalue = (string) wpsc_get_customer_meta('shippingpostcode'); $zip_code_text = __('Your Zipcode', 'wp-e-commerce'); if ($zipvalue != '' && $zipvalue != $zip_code_text) { $color = '#000'; wpsc_update_customer_meta('shipping_zip', $zipvalue); } else { $zipvalue = $zip_code_text; $color = '#999'; } $uses_zipcode = false; $custom_shipping = get_option('custom_shipping_options'); foreach ((array) $custom_shipping as $shipping) { if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) { $uses_zipcode = true; } } if ($uses_zipcode) { $output .= " <input data-wpsc-meta-key='shippingpostcode' class='wpsc-visitor-meta' type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>"; } return $output; }
/** * Echo the country dropdown HTML, presumably for the checkout or customer profile pages * * @param string|array $args * * @return string HTML representation of the dropdown */ function wpsc_country_dropdown($args = '') { echo wpsc_get_country_dropdown($args); }
function wpsc_shipping_country_list($shippingdetails = false) { global $wpdb, $wpsc_shipping_modules, $wpsc_country_data; $js = ''; $output = ''; if (!$shippingdetails) { $output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />"; $js = " onchange='submit_change_country();'"; } $selected_country = (string) wpsc_get_customer_meta('shipping_country'); $selected_region = (string) wpsc_get_customer_meta('shipping_region'); if (empty($selected_country)) { $selected_country = esc_attr(get_option('base_country')); } if (empty($selected_region)) { $selected_region = esc_attr(get_option('base_region')); } if (empty($wpsc_country_data)) { $country_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `visible`= '1' ORDER BY `country` ASC", ARRAY_A); } else { $country_data = $wpsc_country_data; } $acceptable_countries = wpsc_get_acceptable_countries(); $output .= wpsc_get_country_dropdown(array('name' => 'country', 'id' => 'current_country', 'additional_attributes' => $js, 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'placeholder' => '')); $output .= wpsc_shipping_region_list($selected_country, $selected_region, $shippingdetails); if (isset($_POST['wpsc_update_location']) && $_POST['wpsc_update_location'] == 'true') { wpsc_update_customer_meta('update_location', true); } else { wpsc_delete_customer_meta('update_location'); } $zipvalue = (string) wpsc_get_customer_meta('shipping_zip'); if (!empty($_POST['zipcode'])) { $zipvalue = $_POST['zipcode']; } $zip_code_text = __('Your Zipcode', 'wpsc'); if ($zipvalue != '' && $zipvalue != $zip_code_text) { $color = '#000'; wpsc_update_customer_meta('shipping_zip', $zipvalue); } else { $zipvalue = $zip_code_text; $color = '#999'; } $uses_zipcode = false; $custom_shipping = get_option('custom_shipping_options'); foreach ((array) $custom_shipping as $shipping) { if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) { $uses_zipcode = true; } } if ($uses_zipcode) { $output .= " <input type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>"; } return $output; }
function wpsc_country_region_list($form_id = null, $ajax = false, $selected_country = null, $selected_region = null, $supplied_form_id = null, $checkoutfields = false) { global $wpdb; $output = ''; if ($selected_country == null) { $selected_country = get_option('base_country'); } if ($selected_region == null) { $selected_region = get_option('base_region'); } if ($form_id != null) { $html_form_id = "region_country_form_{$form_id}"; } else { $html_form_id = 'region_country_form'; } if ($checkoutfields) { $js = "onchange='set_shipping_country(\"{$html_form_id}\", \"{$form_id}\");'"; $title = 'shippingcountry'; } else { $js = "onchange='set_billing_country(\"{$html_form_id}\", \"{$form_id}\");'"; $title = 'billingcountry'; } $country_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A); $additional_attributes = "title='{$title}' {$js}"; $output .= "<div id='{$html_form_id}'>\n\r"; $output .= wpsc_get_country_dropdown(array('id' => $supplied_form_id, 'name' => "collected_data[{$form_id}][0]", 'class' => 'current_country', 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => '')); $region_list = $wpdb->get_results($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN(%s) AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", $selected_country), ARRAY_A); $sql = "SELECT `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `unique_name` = 'shippingstate' "; $region_form_id = $wpdb->get_var($sql); if ($checkoutfields) { $namevalue = "name='collected_data[" . $region_form_id . "]'"; $js = "onchange='set_shipping_country(\"{$html_form_id}\", \"{$form_id}\");'"; $title = 'shippingstate'; } else { $namevalue = "name='collected_data[" . $form_id . "][1]'"; $js = "onchange='set_billing_country(\"{$html_form_id}\", \"{$form_id}\");'"; $title = 'billingstate'; } $output .= "<div id='region_select_{$form_id}'>"; if ($region_list != null) { $output .= "<select title='{$title}' " . $namevalue . " class='current_region' " . $js . ">\n\r"; foreach ($region_list as $region) { if ($selected_region == $region['id']) { $selected = "selected='selected'"; } else { $selected = ""; } $output .= "<option value='" . $region['id'] . "' {$selected}>" . esc_html($region['name']) . "</option>\n\r"; } $output .= "</select>\n\r"; } $output .= "</div>"; $output .= "</div>\n\r"; return $output; }