Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
    /**
     * form_field method, returns the form html
     * @access public
     */
    function form_field()
    {
        global $wpdb, $user_ID, $wpsc_customer_checkout_details;
        $saved_form_data = empty($wpsc_customer_checkout_details[$this->checkout_item->id]) ? null : $wpsc_customer_checkout_details[$this->checkout_item->id];
        $an_array = '';
        if (function_exists('wpsc_get_ticket_checkout_set')) {
            if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
                $an_array = '[]';
            }
        }
        $output = '';
        $delivery_country = wpsc_get_customer_meta('shippingcountry');
        $billing_country = wpsc_get_customer_meta('billingcountry');
        $delivery_region = wpsc_get_customer_meta('shippingregion');
        $billing_region = wpsc_get_customer_meta('billingregion');
        $meta_key = !empty($this->checkout_item->unique_name) ? $this->checkout_item->unique_name : sanitize_title($this->checkout_item->name) . '_' . $this->checkout_item->id;
        switch ($this->checkout_item->type) {
            case "address":
            case "delivery_address":
            case "textarea":
                $placeholder = apply_filters('wpsc_checkout_field_placeholder', apply_filters('wpsc_checkout_field_name', $this->checkout_item->name), $this->checkout_item);
                $output .= '<textarea data-wpsc-meta-key="' . $meta_key . '" title="' . $this->checkout_item->unique_name . '" class="text wpsc-visitor-meta" id="' . $this->form_element_id() . '" name="collected_data[' . $this->checkout_item->id . ']' . $an_array . '" placeholder="' . esc_attr($placeholder) . '" rows="3" cols="40" >' . esc_textarea((string) $saved_form_data) . '</textarea>';
                break;
            case "checkbox":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $i = mt_rand();
                    foreach ($options as $label => $value) {
                        ?>
							<label>
								<input class="wpsc-visitor-meta" data-wpsc-meta-key="<?php 
                        echo $meta_key;
                        ?>
" <?php 
                        checked(in_array($value, (array) $saved_form_data));
                        ?>
 type="checkbox" name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
[]" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "country":
                $output = wpsc_country_list($this->checkout_item->id, null, $billing_country, $billing_region, $this->form_element_id());
                break;
            case "delivery_country":
                $checkoutfields = true;
                $output = wpsc_country_list($this->checkout_item->id, null, $delivery_country, $delivery_region, $this->form_element_id(), $checkoutfields);
                break;
            case "select":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $output = '<select class="wpsc-visitor-meta" data-wpsc-meta-key="' . $meta_key . '" name="collected_data[' . $this->checkout_item->id . ']"' . $an_array . '">';
                    $output .= "<option value='-1'>" . _x('Select an Option', 'Dropdown default when called within checkout class', 'wp-e-commerce') . "</option>";
                    foreach ((array) $options as $label => $value) {
                        $value = esc_attr(str_replace(' ', '', $value));
                        $output .= "<option " . selected($value, $saved_form_data, false) . " value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r";
                    }
                    $output .= "</select>";
                }
                break;
            case "radio":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    foreach ((array) $options as $label => $value) {
                        ?>
							<label>
								<input class="wpsc-visitor-meta" data-wpsc-meta-key="<?php 
                        echo $meta_key;
                        ?>
" type="radio" <?php 
                        checked($value, $saved_form_data);
                        ?>
 name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "text":
            case "city":
            case "delivery_city":
            case "email":
            case "coupon":
            default:
                if ($this->checkout_item->unique_name == 'shippingstate') {
                    $output .= wpsc_checkout_shipping_state_and_region($this);
                } elseif ($this->checkout_item->unique_name == 'billingstate') {
                    $output .= wpsc_checkout_billing_state_and_region($this);
                } else {
                    $placeholder = apply_filters('wpsc_checkout_field_placeholder', apply_filters('wpsc_checkout_field_name', $this->checkout_item->name), $this->checkout_item);
                    $output = '<input data-wpsc-meta-key="' . $meta_key . '" title="' . $meta_key . '" type="text" id="' . $this->form_element_id() . '" class="text wpsc-visitor-meta" placeholder="' . esc_attr($placeholder) . '" value="' . esc_attr($saved_form_data) . '" name="collected_data[' . $this->checkout_item->id . ']' . $an_array . '" />';
                }
                break;
        }
        return $output;
    }