/**
     * Outputs a form field
     *
     * @param array $args contains a list of args for showing the field, merged with defaults (below)
     * @return string
     */
    public function field($args)
    {
        $defaults = array('type' => 'text', 'name' => '', 'label' => '', 'placeholder' => '', 'required' => false, 'class' => array(), 'label_class' => array(), 'options' => array(), 'selected' => '', 'rel' => '', 'echo' => true, 'return' => false);
        $args = wp_parse_args($args, $defaults);
        if ($args['return']) {
            $args['echo'] = false;
        }
        $required = '';
        $input_required = '';
        $after = '';
        if ($args['name'] == 'billing_state' || $args['name'] == 'shipping_state') {
            if (jigoshop_customer::has_valid_shipping_state()) {
                $args['required'] = false;
            }
        }
        if ($args['required']) {
            $required = ' <span class="required">*</span>';
            $input_required = ' input-required';
        }
        if (in_array('form-row-last', $args['class'])) {
            $after = '<div class="clear"></div>';
        }
        switch ($args['type']) {
            case 'country':
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . esc_attr(implode(' ', $args['label_class'])) . '">' . $args['label'] . $required . '</label>
					<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="country_to_state' . esc_attr($input_required) . '" rel="' . esc_attr($args['rel']) . '">';
                $countries = jigoshop_countries::get_allowed_countries();
                if (Jigoshop_Base::get_options()->get('jigoshop_default_country_for_customer') == -1) {
                    $countries = array_merge(array(-1 => __('Select your country', 'jigoshop')), $countries);
                }
                foreach ($countries as $key => $value) {
                    $field .= '<option value="' . esc_attr($key) . '"';
                    if ($this->get_value($args['name']) == $key) {
                        $field .= ' selected="selected"';
                    } elseif (!$this->get_value($args['name']) && jigoshop_customer::get_country() == $key) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($value, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            case 'state':
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>';
                $allowed_countries = Jigoshop_Base::get_options()->get('jigoshop_allowed_countries');
                $current_cc = $this->get_value($args['rel']);
                if (!$current_cc) {
                    $current_cc = jigoshop_customer::get_country();
                }
                if ($allowed_countries === 'specific') {
                    $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries');
                    $base_cc = jigoshop_countries::get_base_country();
                    if (!in_array($current_cc, $specific_countries)) {
                        if (in_array($base_cc, $specific_countries)) {
                            $current_cc = $base_cc;
                        } else {
                            $current_cc = array_shift($specific_countries);
                        }
                    }
                }
                $current_r = $this->get_value($args['name']);
                if (!$current_r) {
                    $current_r = jigoshop_customer::get_state();
                }
                $states = jigoshop_countries::get_states($current_cc);
                $state_keys = array_keys($states);
                if (jigoshop_countries::country_has_states($current_cc) && !in_array($current_r, $state_keys)) {
                    $base_r = jigoshop_countries::get_base_state();
                    if (in_array($base_r, $state_keys)) {
                        $current_r = $base_r;
                    } else {
                        $current_r = array_shift($state_keys);
                    }
                }
                if (jigoshop_countries::country_has_states($current_cc)) {
                    // Dropdown
                    $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '"><option value="">' . __('Select a state&hellip;', 'jigoshop') . '</option>';
                    foreach ($states as $key => $value) {
                        $field .= '<option value="' . esc_attr($key) . '"';
                        if ($current_r == $key) {
                            $field .= ' selected="selected"';
                        }
                        $field .= '>' . __($value, 'jigoshop') . '</option>';
                    }
                    $field .= '</select>';
                } else {
                    // Input
                    $field .= '<input type="text" class="input-text' . esc_attr($input_required) . '" value="' . esc_attr($current_r) . '" placeholder="' . __('State/Province', 'jigoshop') . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" />';
                }
                $field .= '</p>' . $after;
                break;
            case 'postcode':
                $current_pc = $this->get_value($args['name']);
                if (!$current_pc) {
                    $current_pc = $args['rel'] == 'shipping_country' ? jigoshop_customer::get_shipping_postcode() : jigoshop_customer::get_postcode();
                }
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="text" class="input-text' . esc_attr($input_required) . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . esc_attr($current_pc) . '" rel="' . esc_attr($args['rel']) . '" />
				</p>' . $after;
                break;
            case 'textarea':
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<textarea name="' . esc_attr($args['name']) . '" class="input-text' . esc_attr($input_required) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" cols="5" rows="2" rel="' . esc_attr($args['rel']) . '">' . esc_textarea($this->get_value($args['name'])) . '</textarea>
				</p>' . $after;
                break;
            case 'select':
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="input-text' . esc_attr($input_required) . '" rel="' . esc_attr($args['rel']) . '">';
                foreach ($args['options'] as $key => $value) {
                    $field .= '<option value="' . esc_attr($key) . '"';
                    if (esc_attr($args['selected']) == $key) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($value, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            case 'text':
            case 'password':
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="' . $args['type'] . '" class="input-text' . esc_attr($input_required) . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . $this->get_value($args['name']) . '" rel="' . esc_attr($args['rel']) . '" />
				</p>' . $after;
                break;
            default:
                ob_start();
                do_action('jigoshop_display_checkout_field', $args['type'], $args, $this->get_value($args['name']));
                echo $after;
                $field = ob_get_clean();
                break;
        }
        if ($args['echo']) {
            echo $field;
        }
        return $field;
    }
    /**
     * Outputs a form field
     *
     * @param array $args contains a list of args for showing the field, merged with defaults (below)
     * @return string
     */
    public static function address_form_field($args)
    {
        $defaults = array('type' => 'text', 'name' => '', 'label' => '', 'placeholder' => '', 'required' => false, 'class' => array(), 'label_class' => array(), 'rel' => '', 'return' => false, 'options' => array(), 'value' => '');
        $args = wp_parse_args($args, $defaults);
        if ($args['required']) {
            $required = ' <span class="required">*</span>';
            $input_required = ' input-required';
        } else {
            $required = '';
            $input_required = '';
        }
        if (in_array('form-row-last', $args['class'])) {
            $after = '<div class="clear"></div>';
        } else {
            $after = '';
        }
        switch ($args['type']) {
            case "country":
                $current_c = self::get_value($args['name']);
                $is_shipping_c = strpos($args['name'], 'shipping');
                if (!$current_c) {
                    if ($is_shipping_c === false) {
                        $current_c = jigoshop_customer::get_country();
                    } else {
                        $current_c = jigoshop_customer::get_shipping_country();
                    }
                }
                // Remove 'Select a Country' option from drop-down menu for countries.
                // There is no need to have it, because was assume when user hasn't selected
                // a country that they are from the shop base country.
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
        <label for="' . esc_attr($args['name']) . '" class="' . esc_attr(implode(' ', $args['label_class'])) . '">' . $args['label'] . $required . '</label>
        <select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="country_to_state" rel="' . esc_attr($args['rel']) . '">';
                foreach (jigoshop_countries::get_allowed_countries() as $key => $value) {
                    $field .= '<option value="' . esc_attr($key) . '"';
                    if (self::get_value($args['name']) == $key) {
                        $field .= ' selected="selected"';
                    } elseif (self::get_value($args['name']) && $current_c == $key) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($value, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            case "state":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>';
                $is_shipping_s = strpos($args['name'], 'shipping');
                $current_cc = self::get_value($args['rel']);
                if (!$current_cc) {
                    if ($is_shipping_s === false) {
                        $current_cc = jigoshop_customer::get_country();
                    } else {
                        $current_cc = jigoshop_customer::get_shipping_country();
                    }
                }
                $current_r = self::get_value($args['name']);
                if (!$current_r) {
                    if ($is_shipping_s === false) {
                        $current_r = jigoshop_customer::get_state();
                    } else {
                        $current_r = jigoshop_customer::get_shipping_state();
                    }
                }
                $states = jigoshop_countries::get_states($current_cc);
                if (!empty($states)) {
                    // Dropdown
                    $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '"><option value="">' . __('Select a state&hellip;', 'jigoshop') . '</option>';
                    foreach ($states as $key => $value) {
                        $field .= '<option value="' . esc_attr($key) . '"';
                        if ($current_r == $key) {
                            $field .= ' selected="selected"';
                        }
                        $field .= '>' . __($value, 'jigoshop') . '</option>';
                    }
                    $field .= '</select>';
                } else {
                    // Input
                    $field .= '<input type="text" class="input-text" value="' . esc_attr($current_r) . '" placeholder="' . __('State/Province', 'jigoshop') . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" />';
                }
                $field .= '</p>' . $after;
                break;
            case "postcode":
                $current_pc = self::get_value($args['name']);
                $is_shipping_pc = strpos($args['name'], 'shipping');
                if (!$current_pc) {
                    if ($is_shipping_pc === false) {
                        $current_pc = jigoshop_customer::get_postcode();
                    } else {
                        $current_pc = jigoshop_customer::get_shipping_postcode();
                    }
                }
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="text" class="input-text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . esc_attr($current_pc) . '" />
				</p>' . $after;
                break;
            case "textarea":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<textarea name="' . esc_attr($args['name']) . '" class="input-text' . esc_attr($input_required) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" cols="5" rows="2">' . esc_textarea(self::get_value($args['name'])) . '</textarea>
				</p>' . $after;
                break;
                //Adds a drop down custom type
            //Adds a drop down custom type
            case "select":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
						  <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>';
                $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '">';
                foreach ($args['options'] as $value => $label) {
                    $field .= '<option value="' . esc_attr($value) . '"';
                    if (self::get_value($args['name']) == $value) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($label, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            default:
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="' . $args['type'] . '" class="input-text' . esc_attr($input_required) . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . self::get_value($args['name']) . '" />
				</p>' . $after;
                break;
        }
        $field = apply_filters('jigoshop_address_field_types', $field, $args);
        if ($args['return']) {
            return $field;
        } else {
            echo $field;
            return null;
        }
    }
Exemplo n.º 3
0
	/**
	 * Get the tax rate based on the country and state
	 *
	 * @param   object	Tax Class
	 * @return  mixed		
	 */
	function get_shipping_tax_rate( $tax_class = '' ) {
		
		if (defined('JIGOSHOP_CHECKOUT') && JIGOSHOP_CHECKOUT) :
			$country 	= jigoshop_customer::get_country();
			$state 		= jigoshop_customer::get_state();
		else :
			$country 	= jigoshop_countries::get_base_country();
			$state 		= jigoshop_countries::get_base_state();
		endif;
		
		// If we are here then shipping is taxable - work it out
		
		if ($tax_class) :
			
			// This will be per item shipping
			$rate = $this->find_rate( $country, $state, $tax_class );
			
			if (isset($rate['shipping']) && $rate['shipping']=='yes') :
				return $rate['rate'];
			else :
				// Get standard rate
				$rate = $this->find_rate( $country, $state );
				if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
			endif;
			
		else :
			
			// This will be per order shipping - loop through the order and find the highest tax class rate
			
			$found_rates = array();
			$found_shipping_rates = array();
			
			// Loop cart and find the highest tax band
			if (sizeof(jigoshop_cart::$cart_contents)>0) : foreach (jigoshop_cart::$cart_contents as $item) :
				
				if ($item['data']->data['tax_class']) :
					
					$found_rate = $this->find_rate( $country, $state, $item['data']->data['tax_class'] );
					
					$found_rates[] = $found_rate['rate'];
					
					if (isset($found_rate['shipping']) && $found_rate['shipping']=='yes') $found_shipping_rates[] = $found_rate['rate'];
					
				endif;
				
			endforeach; endif;
			
			if (sizeof($found_rates) > 0 && sizeof($found_shipping_rates) > 0) :
				
				rsort($found_rates);
				rsort($found_shipping_rates);
				
				if ($found_rates[0] == $found_shipping_rates[0]) :
					return $found_shipping_rates[0];
				else :
					// Use standard rate
					$rate = $this->find_rate( $country, $state );
					if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
				endif;
				
			else :
				// Use standard rate
				$rate = $this->find_rate( $country, $state );	
				if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
			endif;
			
		endif;

		return 0; // return false
	}
Exemplo n.º 4
0
 /**
  * @return string Customer state to be used as base for taxes.
  */
 public static function get_customer_state()
 {
     if (Jigoshop_Base::get_options()->get('jigoshop_country_base_tax') == 'shipping_country') {
         return jigoshop_customer::get_shipping_state();
     }
     return jigoshop_customer::get_state();
 }
Exemplo n.º 5
0
function jigoshop_frontend_scripts()
{
    $options = Jigoshop_Base::get_options();
    $frontend_css = JIGOSHOP_URL . '/assets/css/frontend.css';
    $theme_css = file_exists(get_stylesheet_directory() . '/jigoshop/style.css') ? get_stylesheet_directory_uri() . '/jigoshop/style.css' : $frontend_css;
    if ($options->get('jigoshop_disable_css') == 'no') {
        if ($options->get('jigoshop_frontend_with_theme_css') == 'yes' && $frontend_css != $theme_css) {
            jrto_enqueue_style('frontend', 'jigoshop_theme_styles', $frontend_css);
        }
        jrto_enqueue_style('frontend', 'jigoshop_styles', $theme_css);
    }
    wp_enqueue_script('jquery');
    wp_register_script('jquery-blockui', '//cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.min.js', array('jquery'), '2.66.0');
    wp_enqueue_script('jquery-blockui');
    jrto_enqueue_script('frontend', 'jigoshop_global', JIGOSHOP_URL . '/assets/js/global.js', array('jquery'), array('in_footer' => true));
    if ($options->get('jigoshop_disable_fancybox') == 'no') {
        jrto_enqueue_script('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/js/jquery.prettyPhoto.js', array('jquery'), array('in_footer' => true));
        jrto_enqueue_style('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/css/prettyPhoto.css');
    }
    jrto_enqueue_script('frontend', 'jigoshop-cart', JIGOSHOP_URL . '/assets/js/cart.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_CART));
    jrto_enqueue_script('frontend', 'jigoshop-checkout', JIGOSHOP_URL . '/assets/js/checkout.js', array('jquery', 'jquery-blockui'), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_PAY)));
    jrto_enqueue_script('frontend', 'jigoshop-validation', JIGOSHOP_URL . '/assets/js/validation.js', array(), array('in_footer' => true, 'page' => JIGOSHOP_CHECKOUT));
    jrto_enqueue_script('frontend', 'jigoshop-payment', JIGOSHOP_URL . '/assets/js/pay.js', array('jquery'), array('page' => JIGOSHOP_PAY));
    jrto_enqueue_script('frontend', 'jigoshop-single-product', JIGOSHOP_URL . '/assets/js/single-product.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_PRODUCT));
    jrto_enqueue_script('frontend', 'jigoshop-countries', JIGOSHOP_URL . '/assets/js/countries.js', array(), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_CART, JIGOSHOP_EDIT_ADDRESS)));
    /* Script.js variables */
    // TODO: clean this up, a lot aren't even used anymore, do away with it
    $jigoshop_params = array('ajax_url' => admin_url('admin-ajax.php', 'jigoshop'), 'assets_url' => JIGOSHOP_URL, 'validate_postcode' => $options->get('jigoshop_enable_postcode_validating', 'no'), 'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout', 'jigoshop'), 'currency_symbol' => get_jigoshop_currency_symbol(), 'get_variation_nonce' => wp_create_nonce("get-variation"), 'load_fancybox' => $options->get('jigoshop_disable_fancybox') == 'no', 'option_guest_checkout' => $options->get('jigoshop_enable_guest_checkout'), 'select_state_text' => __('Select a state&hellip;', 'jigoshop'), 'state_text' => __('state', 'jigoshop'), 'ratings_message' => __('Please select a star to rate your review.', 'jigoshop'), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'billing_state' => jigoshop_customer::get_state(), 'shipping_state' => jigoshop_customer::get_shipping_state(), 'is_checkout' => is_page(jigoshop_get_page_id('checkout')) || is_page(jigoshop_get_page_id('pay')), 'error_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_error_disappear_time', 8000), 'message_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_message_disappear_time', 4000));
    if (isset(jigoshop_session::instance()->min_price)) {
        $jigoshop_params['min_price'] = $_GET['min_price'];
    }
    if (isset(jigoshop_session::instance()->max_price)) {
        $jigoshop_params['max_price'] = $_GET['max_price'];
    }
    $jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);
    jrto_localize_script('jigoshop_global', 'jigoshop_params', $jigoshop_params);
}
Exemplo n.º 6
0
function jigoshop_edit_address() {
	
	$user_id = get_current_user_id();
	
	if (is_user_logged_in()) :
		
		if (isset($_GET['address'])) $load_address = $_GET['address']; else $load_address = 'billing';
		if ($load_address == 'billing') $load_address = 'billing'; else $load_address = 'shipping';
		
		if ($_POST) :
		
			if ($user_id>0 && jigoshop::verify_nonce('edit_address') ) :
				update_user_meta( $user_id, $load_address . '-first_name', jigowatt_clean($_POST['address-first_name']) );
				update_user_meta( $user_id, $load_address . '-last_name', jigowatt_clean($_POST['address-last_name']) );
				update_user_meta( $user_id, $load_address . '-company', jigowatt_clean($_POST['address-company']) );
				update_user_meta( $user_id, $load_address . '-email', jigowatt_clean($_POST['address-email']) );
				update_user_meta( $user_id, $load_address . '-address', jigowatt_clean($_POST['address-address']) );
				update_user_meta( $user_id, $load_address . '-address2', jigowatt_clean($_POST['address-address2']) );
				update_user_meta( $user_id, $load_address . '-city', jigowatt_clean($_POST['address-city']) );
				update_user_meta( $user_id, $load_address . '-postcode', jigowatt_clean($_POST['address-postcode']) );
				update_user_meta( $user_id, $load_address . '-country', jigowatt_clean($_POST['address-country']) );
				update_user_meta( $user_id, $load_address . '-state', jigowatt_clean($_POST['address-state']) );
				update_user_meta( $user_id, $load_address . '-phone', jigowatt_clean($_POST['address-phone']) );
				update_user_meta( $user_id, $load_address . '-fax', jigowatt_clean($_POST['address-fax']) );
			endif;
			
			wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
			exit;
		
		endif;
		
		$address = array(
			'first_name' => get_user_meta( get_current_user_id(), $load_address . '-first_name', true ),
			'last_name' => get_user_meta( get_current_user_id(), $load_address . '-last_name', true ),
			'company' => get_user_meta( get_current_user_id(), $load_address . '-company', true ),
			'email' => get_user_meta( get_current_user_id(), $load_address . '-email', true ),
			'phone' => get_user_meta( get_current_user_id(), $load_address . '-phone', true ),
			'fax' => get_user_meta( get_current_user_id(), $load_address . '-fax', true ),
			'address' => get_user_meta( get_current_user_id(), $load_address . '-address', true ),
			'address2' => get_user_meta( get_current_user_id(), $load_address . '-address2', true ),
			'city' => get_user_meta( get_current_user_id(), $load_address . '-city', true ),		
			'state' => get_user_meta( get_current_user_id(), $load_address . '-state', true ),
			'postcode' => get_user_meta( get_current_user_id(), $load_address . '-postcode', true ),
			'country' => get_user_meta( get_current_user_id(), $load_address . '-country', true )
		);
		?>
		<form action="<?php echo add_query_arg('address', $load_address, get_permalink(get_option('jigoshop_edit_address_page_id'))); ?>" method="post">
	
			<h3><?php if ($load_address=='billing') _e('Billing Address', 'jigoshop'); else _e('Shipping Address', 'jigoshop'); ?></h3>
			
			<p class="form-row form-row-first">
				<label for="address-first_name"><?php _e('First Name', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-first_name" id="address-first_name" placeholder="<?php _e('First Name', 'jigoshop'); ?>" value="<?php echo $address['first_name']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-last_name"><?php _e('Last Name', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-last_name" id="address-last_name" placeholder="<?php _e('Last Name', 'jigoshop'); ?>" value="<?php echo $address['last_name']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row columned">
				<label for="address-company"><?php _e('Company', 'jigoshop'); ?></label>
				<input type="text" class="input-text" name="address-company" id="address-company" placeholder="<?php _e('Company', 'jigoshop'); ?>" value="<?php echo $address['company']; ?>" />
			</p>
			
			<p class="form-row form-row-first">
				<label for="address-address"><?php _e('Address', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-address" id="address-address" placeholder="<?php _e('1 Infinite Loop', 'jigoshop'); ?>" value="<?php echo $address['address']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-address2" class="hidden"><?php _e('Address 2', 'jigoshop'); ?></label>
				<input type="text" class="input-text" name="address-address2" id="address-address2" placeholder="<?php _e('Cupertino', 'jigoshop'); ?>" value="<?php echo $address['address2']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row form-row-first">
				<label for="address-city"><?php _e('City', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-city" id="address-city" placeholder="<?php _e('City', 'jigoshop'); ?>" value="<?php echo $address['city']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-postcode"><?php _e('Postcode', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-postcode" id="address-postcode" placeholder="123456" value="<?php echo $address['postcode']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row form-row-first">
				<label for="address-country"><?php _e('Country', 'jigoshop'); ?> <span class="required">*</span></label>
				<select name="address-country" id="address-country" class="country_to_state" rel="address-state">
					<option value=""><?php _e('Select a country&hellip;', 'jigoshop'); ?></option>
					<?php						
						foreach(jigoshop_countries::$countries as $key=>$value) :
							echo '<option value="'.$key.'"';
							if ($address['country']==$key) echo 'selected="selected"';
							elseif (!$address['country'] && jigoshop_customer::get_country()==$key) echo 'selected="selected"';
							echo '>'.$value.'</option>';
						endforeach;
					?>
				</select>
			</p>
			<p class="form-row form-row-last">	
				<label for="address-state"><?php _e('state', 'jigoshop'); ?> <span class="required">*</span></label>
				<?php 
					$current_cc = $address['country'];
					if (!$current_cc) $current_cc = jigoshop_customer::get_country();
					
					$current_r = $address['state'];
					if (!$current_r) $current_r = jigoshop_customer::get_state();
					
					$states = jigoshop_countries::$states;
					
					if (isset( $states[$current_cc][$current_r] )) :
						// Dropdown
						?>
						<select name="address-state" id="address-state"><option value=""><?php _e('Select a state&hellip;', 'jigoshop'); ?></option><?php
								foreach($states[$current_cc] as $key=>$value) :
									echo '<option value="'.$key.'"';
									if ($current_r==$key) echo 'selected="selected"';
									echo '>'.$value.'</option>';
								endforeach;
						?></select>
						<?php
					else :
						// Input
						?><input type="text" class="input-text" value="<?php echo $current_r; ?>" placeholder="<?php _e('state', 'jigoshop'); ?>" name="address-state" id="address-state" /><?php
					endif;
				?>
			</p>
			<div class="clear"></div>
			
			<?php if ($load_address=='billing') : ?>
				<p class="form-row columned">
					<label for="address-email"><?php _e('Email Address', 'jigoshop'); ?> <span class="required">*</span></label>
					<input type="text" class="input-text" name="address-email" id="address-email" placeholder="<?php _e('*****@*****.**', 'jigoshop'); ?>" value="<?php echo $address['email']; ?>" />
				</p>
				
				<p class="form-row form-row-first">
					<label for="address-phone"><?php _e('Phone', 'jigoshop'); ?> <span class="required">*</span></label>
					<input type="text" class="input-text" name="address-phone" id="address-phone" placeholder="0123456789" value="<?php echo $address['phone']; ?>" />
				</p>
				<p class="form-row form-row-last">	
					<label for="address-fax"><?php _e('Fax', 'jigoshop'); ?></label>
					<input type="text" class="input-text" name="address-fax" id="address-fax" placeholder="0123456789" value="<?php echo $address['fax']; ?>" />
				</p>
				<div class="clear"></div>
			<?php endif; ?>
			<?php jigoshop::nonce_field('edit_address') ?>
			<input type="submit" class="button" name="save_address" value="<?php _e('Save Address', 'jigoshop'); ?>" />
	
		</form>
		<?php
		
	else :
	
		wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
		exit;
		
	endif;
}
	/**
	 * Outputs a form field
	 *
	 * @param   array	args	contains a list of args for showing the field, merged with defaults (below)
	 */
	function checkout_form_field( $args ) {
		
		$defaults = array(
			'type' => 'input',
			'name' => '',
			'label' => '',
			'placeholder' => '',
			'required' => false,
			'class' => array(),
			'label_class' => array(),
			'rel' => '',
			'return' => false
		);
		
		$args = wp_parse_args( $args, $defaults );

		if ($args['required']) $required = ' <span class="required">*</span>'; else $required = '';
		
		if (in_array('form-row-last', $args['class'])) $after = '<div class="clear"></div>'; else $after = '';
		
		$field = '';
		
		switch ($args['type']) :
			case "country" :
				
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>
					<select name="'.$args['name'].'" id="'.$args['name'].'" class="country_to_state" rel="'.$args['rel'].'">
						<option value="">'.__('Select a country&hellip;', 'jigoshop').'</option>';
				
				foreach(jigoshop_countries::get_allowed_countries() as $key=>$value) :
					$field .= '<option value="'.$key.'"';
					if ($this->get_value($args['name'])==$key) $field .= 'selected="selected"';
					elseif (!$this->get_value($args['name']) && jigoshop_customer::get_country()==$key) $field .= 'selected="selected"';
					$field .= '>'.__($value, 'jigoshop').'</option>';
				endforeach;
				
				$field .= '</select></p>'.$after;

			break;
			case "state" :
				
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>';
					
				$current_cc = $this->get_value($args['rel']);
				if (!$current_cc) $current_cc = jigoshop_customer::get_country();
				
				$current_r = $this->get_value($args['name']);
				if (!$current_r) $current_r = jigoshop_customer::get_state();
				
				$states = jigoshop_countries::$states;	
					
				if (isset( $states[$current_cc][$current_r] )) :
					// Dropdown
					$field .= '<select name="'.$args['name'].'" id="'.$args['name'].'"><option value="">'.__('Select a state&hellip;', 'jigoshop').'</option>';
					foreach($states[$current_cc] as $key=>$value) :
						$field .= '<option value="'.$key.'"';
						if ($current_r==$key) $field .= 'selected="selected"';
						$field .= '>'.__($value, 'jigoshop').'</option>';
					endforeach;
					$field .= '</select>';
				else :
					// Input
					$field .= '<input type="text" class="input-text" value="'.$current_r.'" placeholder="'.__('State/County', 'jigoshop').'" name="'.$args['name'].'" id="'.$args['name'].'" />';
				endif;
	
				$field .= '</p>'.$after;
				
			break;
			case "textarea" :
				
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>
					<textarea name="'.$args['name'].'" class="input-text" id="'.$args['name'].'" placeholder="'.$args['placeholder'].'" cols="5" rows="2">'. $this->get_value( $args['name'] ).'</textarea>
				</p>'.$after;
				
			break;
			default :
			
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>
					<input type="'.$args['type'].'" class="input-text" name="'.$args['name'].'" id="'.$args['name'].'" placeholder="'.$args['placeholder'].'" value="'. $this->get_value( $args['name'] ).'" />
				</p>'.$after;
				
			break;
		endswitch;
		
		if ($args['return']) return $field; else echo $field;
	}