示例#1
0
function get_order_email_arguments($order_id)
{
    $options = Jigoshop_Base::get_options();
    $order = new jigoshop_order($order_id);
    $inc_tax = $options->get('jigoshop_calc_taxes') == 'no' || $options->get('jigoshop_prices_include_tax') == 'yes';
    $can_show_links = $order->status == 'completed' || $order->status == 'processing';
    $statuses = $order->get_order_statuses_and_names();
    $variables = array('blog_name' => get_bloginfo('name'), 'order_number' => $order->get_order_number(), 'order_date' => date_i18n(get_option('date_format')), 'order_status' => $statuses[$order->status], 'shop_name' => $options->get('jigoshop_company_name'), 'shop_address_1' => $options->get('jigoshop_address_1'), 'shop_address_2' => $options->get('jigoshop_address_2'), 'shop_tax_number' => $options->get('jigoshop_tax_number'), 'shop_phone' => $options->get('jigoshop_company_phone'), 'shop_email' => $options->get('jigoshop_company_email'), 'customer_note' => $order->customer_note, 'order_items_table' => jigoshop_get_order_items_table($order, $can_show_links, true, $inc_tax), 'order_items' => $order->email_order_items_list($can_show_links, true, $inc_tax), 'order_taxes' => jigoshop_get_order_taxes_list($order), 'subtotal' => $order->get_subtotal_to_display(), 'shipping' => $order->get_shipping_to_display(), 'shipping_cost' => jigoshop_price($order->order_shipping), 'shipping_method' => $order->shipping_service, 'discount' => jigoshop_price($order->order_discount), 'applied_coupons' => jigoshop_get_order_coupon_list($order), 'total_tax' => jigoshop_price($order->get_total_tax()), 'total' => jigoshop_price($order->order_total), 'is_local_pickup' => $order->shipping_method == 'local_pickup' ? true : null, 'checkout_url' => $order->status == 'pending' ? $order->get_checkout_payment_url() : null, 'payment_method' => $order->payment_method_title, 'is_bank_transfer' => $order->payment_method == 'bank_transfer' ? true : null, 'is_cash_on_delivery' => $order->payment_method == 'cod' ? true : null, 'is_cheque' => $order->payment_method == 'cheque' ? true : null, 'bank_info' => str_replace(PHP_EOL, '', jigoshop_bank_transfer::get_bank_details()), 'cheque_info' => str_replace(PHP_EOL, '', $options->get('jigoshop_cheque_description')), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_euvatno' => $order->billing_euvatno, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_country' => jigoshop_countries::get_country($order->billing_country), 'billing_state' => strlen($order->billing_state) == 2 ? jigoshop_countries::get_state($order->billing_country, $order->billing_state) : $order->billing_state, 'billing_country_raw' => $order->billing_country, 'billing state_raw' => $order->billing_state, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_country' => jigoshop_countries::get_country($order->shipping_country), 'shipping_state' => strlen($order->shipping_state) == 2 ? jigoshop_countries::get_state($order->shipping_country, $order->shipping_state) : $order->shipping_state, 'shipping_country_raw' => $order->shipping_country, 'shipping_state_raw' => $order->shipping_state);
    if ($options->get('jigoshop_calc_taxes') == 'yes') {
        $variables['all_tax_classes'] = $variables['order_taxes'];
    } else {
        unset($variables['order_taxes']);
    }
    return apply_filters('jigoshop_order_email_variables', $variables, $order_id);
}
示例#2
0
			<h3><?php 
    _e('Shipping Address', 'jigoshop');
    ?>
</h3>
			<a href="<?php 
    echo esc_url(add_query_arg('address', 'shipping', apply_filters('jigoshop_get_edit_address_page_id', get_permalink(jigoshop_get_page_id('edit_address')))));
    ?>
" class="edit"><?php 
    _e('Edit', 'jigoshop');
    ?>
</a>
		</header>
		<address>
			<?php 
    $country = get_user_meta(get_current_user_id(), 'shipping_country', true);
    $country = jigoshop_countries::has_country($country) ? jigoshop_countries::get_country($country) : '';
    $address = array(get_user_meta(get_current_user_id(), 'shipping_first_name', true) . ' ' . get_user_meta(get_current_user_id(), 'shipping_last_name', true), get_user_meta(get_current_user_id(), 'shipping_company', true), get_user_meta(get_current_user_id(), 'shipping_address_1', true), get_user_meta(get_current_user_id(), 'shipping_address_2', true), get_user_meta(get_current_user_id(), 'shipping_city', true), get_user_meta(get_current_user_id(), 'shipping_state', true), get_user_meta(get_current_user_id(), 'shipping_postcode', true), $country);
    $address = array_map('trim', $address);
    $formatted_address = implode(', ', array_filter($address));
    if (!$formatted_address) {
        _e('You have not set up a shipping address yet.', 'jigoshop');
    } else {
        echo $formatted_address;
    }
    ?>
		</address>
	</div>
</div>
<?php 
    do_action('jigoshop_after_my_account');
} else {
/**
 * Execute changes made in Jigoshop 1.0
 *
 * @since 1.0.0
 */
function jigoshop_upgrade_100() {
	global $wpdb;

	// Run upgrade

    // upgrade option jigoshop_tax_rates
    $jigoshop_tax_rates = get_site_option('jigoshop_tax_rates');
    $tax_rates = array();

    if ($jigoshop_tax_rates && is_array($jigoshop_tax_rates)) :

        foreach($jigoshop_tax_rates as $key) :
            $country = $key['country'];
            $state = $key['state'];

            // Change canadian province NF and PQ to NL and QC respectively
            if (isset($key['country']) && $key['country'] == 'CA') :
                if ($key['state'] == 'NF') :
                    $state = 'NL';
                elseif ($key['state'] == 'PQ') :
                    $state = 'QC';
                endif;
            endif;

            $rate = $key['rate'];
            $shipping = $key['shipping'];
            $class = $key['class'];

            // convert all-states
            if (jigoshop_countries::country_has_states($country) && $state == '*') :
                foreach (array_keys(jigoshop_countries::$states[$country]) as $st) :
                    $tax_rates[] = array(
									'country'      => $country,
									'label'        => '', // no label created as of yet
									'state'        => $st,
									'rate'         => $rate,
									'shipping'     => $shipping,
									'class'        => $class,
									'compound'     => 'no', //no such thing as compound taxes, so value is no
									'is_all_states'=> true //determines if admin panel should show 'all_states'
                                );
                endforeach;

            else : // do normal tax_rates array with the additional parameters
                    $tax_rates[] = array(
									'country'      => $country,
									'label'        => '', // no label created as of yet
									'state'        => $state,
									'rate'         => $rate,
									'shipping'     => $shipping,
									'class'        => $class,
									'compound'     => 'no', //no such thing as compound taxes, so value is no
									'is_all_states'=> false //determines if admin panel should show 'all_states'
                                );

            endif;
        endforeach;

        update_option('jigoshop_tax_rates', $tax_rates);

    endif;

    // convert products

	$args = array(
		'post_type'	  => 'product',
		'numberposts' => -1,
		'post_status' => 'any', // Fixes draft products not being upgraded
	);

	$posts = get_posts( $args );

	foreach( $posts as $post ) {

		// Convert SKU key to lowercase
		$wpdb->update( $wpdb->postmeta, array('meta_key' => 'sku'), array('post_id' => $post->ID, 'meta_key' => 'sku') );

		// Change redirect add to cart option name
		$checkoutValue = get_option( 'jigoshop_directly_to_checkout' );

		if ($checkoutValue == "no" )
			$checkoutValue = "same_page";

		else if ($checkoutValue == "cart")
			$checkoutValue = "to_cart";

		else if ($checkoutValue == "yes")
			$checkoutValue = "to_checkout";

		update_option( 'jigoshop_redirect_add_to_cart' , $checkoutValue );
		delete_option( 'jigoshop_directly_to_checkout' );

		// Convert featured to true/false
		$featured = get_post_meta( $post->ID, 'featured', true);

		if ( $featured == 'yes' )
			update_post_meta( $post->ID, 'featured', true );
		else {
			update_post_meta( $post->ID, 'featured', false);
		}

		// Convert the filepath to url
		$file_path = get_post_meta( $post->ID, 'file_path', true );
		update_post_meta( $post->ID, 'file_path', site_url().'/'.$file_path );

		// Unserialize all product_data keys to individual key => value pairs
		$product_data = get_post_meta( $post->ID, 'product_data', true );
		if ( is_array($product_data) ) {
			foreach( $product_data as $key => $value ) {

				// Convert all keys to lowercase
				// @todo: Needs testing especially with 3rd party plugins using product_data
				$key = strtolower($key);

				// We now call it tax_classes & its an array
				if ( $key == 'tax_class' ) {

					if ( $value )
						$value = (array) $value;
					else
						$value = array('*');

					$key = 'tax_classes';
				}

				// Convert manage stock to true/false
				if ( $key == 'manage_stock' ) {
					$value = ( $value == 'yes' ) ? true : false;
				}

				// Create the meta
				update_post_meta( $post->ID, $key, $value );

				// Remove the old meta
				delete_post_meta( $post->ID, 'product_data' );
			}
		}

		$product_attributes = get_post_meta( $post->ID, 'product_attributes', true );

		if ( is_array($product_attributes) ) {
			foreach( $product_attributes as $key => $attribute ) {

				// We use true/false for these now
				if ( isset( $attribute['visible'] ) )
					$attribute['visible']     = ( $attribute['visible'] == 'yes' ) ? true : false;

				if ( isset( $attribute['variation'] ) )
					$attribute['variation']   = ( $attribute['variation'] == 'yes' ) ? true : false;

				if ( isset( $attribute['is_taxonomy'] ) )
					$attribute['is_taxonomy'] = ( $attribute['is_taxonomy'] == 'yes' ) ? true : false;

				$product_attributes[$key] = $attribute;
			}

			update_post_meta( $post->ID, 'product_attributes', $product_attributes );
		}
	}

	// Variations
	$args = array(
		'post_type'	  => 'product_variation',
		'numberposts' => -1,
		'post_status' => 'any', // Fixes draft products not being upgraded
	);

	$posts = get_posts( $args );

	foreach( $posts as $post ) {

		// Convert SKU key to lowercase
		$wpdb->update( $wpdb->postmeta, array('meta_key' => 'sku'), array('post_id' => $post->ID, 'meta_key' => 'sku') );

		// Convert 'price' key to regular_price
		$wpdb->update( $wpdb->postmeta, array('meta_key' => 'regular_price'), array('post_id' => $post->ID, 'meta_key' => 'price') );

		$taxes = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key LIKE %s", $post->ID, 'tax_%' ) );

		// Update catch all prices, weights, and dimensions
		$parent_id = $post->post_parent;
		$parent_reg_price = get_post_meta( $parent_id, 'regular_price', true );
		$parent_sale_price = get_post_meta( $parent_id, 'sale_price', true );

        // weight and dimensions were in pre 1.0. Therefore, make sure all of this
        // data gets converted as well
		$parent_weight = get_post_meta( $parent_id, 'weight', true );
		$parent_length = get_post_meta( $parent_id, 'length', true );
		$parent_height = get_post_meta( $parent_id, 'height', true );
		$parent_width  = get_post_meta( $parent_id, 'width',  true );

		if ( ! get_post_meta( $post->ID, 'regular_price', true) && $parent_reg_price )
			update_post_meta( $post->ID, 'regular_price', $parent_reg_price );

		if( ! get_post_meta( $post->ID, 'sale_price', true) && $parent_sale_price )
			update_post_meta( $post->ID, 'sale_price', $parent_sale_price );

		if( ! get_post_meta( $post->ID, 'weight', true) && $parent_weight )
			update_post_meta( $post->ID, 'weight', $parent_weight );

		if( ! get_post_meta( $post->ID, 'length', true) && $parent_length )
			update_post_meta( $post->ID, 'length', $parent_length );

		if( ! get_post_meta( $post->ID, 'height', true) && $parent_height )
			update_post_meta( $post->ID, 'height', $parent_height );

		if( ! get_post_meta( $post->ID, 'width', true) && $parent_width )
			update_post_meta( $post->ID, 'width', $parent_width );

		$variation_data = array();
		foreach( $taxes as $tax ) {
			$variation_data[$tax->meta_key] = $tax->meta_value;
			delete_post_meta( $post->ID, $tax->meta_key );
		}

		update_post_meta( $post->ID, 'variation_data', $variation_data );
	}

	// Update shop order comments type
	$wpdb->update( $wpdb->comments, array(
		'comment_type' => 'jigoshop',
		'comment_author' => 'Jigoshop',
		'comment_author_email' => '',
		'comment_author_IP' => '',
	), array('user_id' => 0, 'comment_author' => 'JigoShop') );
}
示例#4
0
    function column_default($user, $column_name)
    {
        switch ($column_name) {
            case 'customer_name':
                if ($user->last_name && $user->first_name) {
                    return $user->last_name . ', ' . $user->first_name;
                } else {
                    return '-';
                }
            case 'username':
                return $user->user_login;
            case 'location':
                $state_code = get_user_meta($user->ID, 'billing_state', true);
                $country_code = get_user_meta($user->ID, 'billing_country', true);
                $state = jigoshop_countries::has_state($country_code, $state_code) ? jigoshop_countries::get_state($country_code, $state_code) : $state_code;
                $country = jigoshop_countries::has_country($country_code) ? jigoshop_countries::get_country($country_code) : $country_code;
                $value = '';
                if ($state) {
                    $value .= $state . ', ';
                }
                $value .= $country;
                if ($value) {
                    return $value;
                } else {
                    return '-';
                }
            case 'email':
                return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
            case 'spent':
                return jigoshop_price(jigoshop_get_customer_total_spent($user->ID));
            case 'orders':
                return jigoshop_get_customer_order_count($user->ID);
            case 'last_order':
                $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => array('publish'), 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'customer_user', 'value' => $user->ID)), 'fields' => 'ids'));
                if ($order_ids) {
                    $order = new jigoshop_order($order_ids[0]);
                    return '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order->get_order_number() . '</a> &ndash; ' . date_i18n(get_option('date_format'), strtotime($order->order_date));
                } else {
                    return '-';
                }
                break;
            case 'user_actions':
                ob_start();
                ?>
<p>
				<?php 
                do_action('jigoshop_admin_user_actions_start', $user);
                $actions = array();
                $actions['refresh'] = array('url' => wp_nonce_url(add_query_arg('refresh', $user->ID), 'refresh'), 'name' => __('Refresh stats', 'jigoshop'), 'action' => 'refresh');
                $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'jigoshop'), 'action' => 'edit');
                $order_ids = $this->get_guest_orders();
                $order_ids = array_map(function ($order) {
                    return $order->ID;
                }, array_filter($order_ids, function ($order) use($user) {
                    return $order->data['billing_email'] == $user->user_email;
                }));
                if ($order_ids) {
                    $actions['link'] = array('url' => wp_nonce_url(add_query_arg('link_orders', $user->ID), 'link_orders'), 'name' => __('Link previous orders', 'jigoshop'), 'action' => 'link');
                }
                $actions = apply_filters('jigoshop_admin_user_actions', $actions, $user);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                do_action('jigoshop_admin_user_actions_end', $user);
                ?>
				</p><?php 
                $user_actions = ob_get_contents();
                ob_end_clean();
                return $user_actions;
        }
        return '';
    }
 function jigoshop_eu_b2b_vat_message()
 {
     if (jigoshop_countries::is_eu_country(jigoshop_customer::get_country()) && Jigoshop_Base::get_options()->get('jigoshop_eu_vat_reduction_message') == 'yes') {
         echo '<div class="clear"></div><div class="payment_message">' . __('If you have entered an EU VAT Number, it will be looked up when you <strong>Place</strong> your Order and verified.  At that time <strong><em>Only</em></strong>, will VAT then be removed from the final Order and totals adjusted.  You may enter your EU VAT Number either with, or without, the 2 character EU country code in front.', 'jigoshop') . '</div>';
     }
 }
	/**
	 * 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;
	}
    function format_tax_rates_for_display($value)
    {
        $_tax = new jigoshop_tax();
        $tax_classes = $_tax->get_tax_classes();
        $tax_rates = Jigoshop_Base::get_options()->get('jigoshop_tax_rates');
        if (empty($tax_rates)) {
            $tax_rates = array();
        }
        $applied_all_states = array();
        ob_start();
        ?>
		<div id="jigoshop_tax_rates">
			<table class="tax_rate_rules" cellspacing="0">
				<thead>
					<tr>
						<th><?php 
        _e('Remove', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Tax Classes', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Online Label', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Country/State', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e("Rate (%)", 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Apply to shipping', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Compound', 'jigoshop');
        ?>
</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th><?php 
        _e('Remove', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Tax Classes', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Online Label', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Country/State', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e("Rate (%)", 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Apply to shipping', 'jigoshop');
        ?>
</th>
						<th><?php 
        _e('Compound', 'jigoshop');
        ?>
</th>
					</tr>
				</tfoot>
				<tbody>
					<?php 
        $i = -1;
        if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) {
            $tax_rates = $this->array_compare($tax_rates);
            foreach ($tax_rates as $rate) {
                if (isset($rate['is_all_states']) && in_array($rate['country'] . $rate['class'], $applied_all_states)) {
                    continue;
                }
                $i++;
                // increment counter after check for all states having been applied
                echo '<tr class="tax_rate"><td><a href="#" class="remove button">&times;</a></td>';
                echo '<td><select id="tax_classes[' . esc_attr($i) . ']" name="tax_classes[' . esc_attr($i) . ']"><option value="*">' . __('Standard Rate', 'jigoshop') . '</option>';
                if ($tax_classes) {
                    foreach ($tax_classes as $class) {
                        echo '<option value="' . sanitize_title($class) . '"';
                        if (isset($rate['class']) && $rate['class'] == sanitize_title($class)) {
                            echo 'selected="selected"';
                        }
                        echo '>' . $class . '</option>';
                    }
                }
                echo '</select></td>';
                echo '<td><input type="text" value="' . esc_attr($rate['label']) . '" name="tax_label[' . esc_attr($i) . ']" placeholder="' . __('Online Label', 'jigoshop') . '" size="10" /></td>';
                echo '<td><select name="tax_country[' . esc_attr($i) . '][]" id="tax_country_' . esc_attr($i) . '" class="tax_select2" multiple="multiple" style="width:220px;">';
                if (isset($rate['is_all_states'])) {
                    if (is_array($applied_all_states) && !in_array($rate['country'] . $rate['class'], $applied_all_states)) {
                        $applied_all_states[] = $rate['country'] . $rate['class'];
                        jigoshop_countries::country_dropdown_options($rate['country'], '*', true);
                        //all-states
                    } else {
                        continue;
                    }
                } else {
                    jigoshop_countries::country_dropdown_options($rate['country'], $rate['state'], true);
                }
                echo '</select>';
                echo '<button class="select_none button">' . __('None', 'jigoshop') . '</button><button class="button select_all">' . __('All', 'jigoshop') . '</button><button class="button select_us_states">' . __('US States', 'jigoshop') . '</button><button class="button select_europe">' . __('EU States', 'jigoshop') . '</button></td>';
                echo '<td><input type="text" value="' . esc_attr($rate['rate']) . '" name="tax_rate[' . esc_attr($i) . ']" placeholder="' . __('Rate (%)', 'jigoshop') . '" size="6" /></td>';
                echo '<td><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" ';
                if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                    echo 'checked="checked"';
                }
                echo ' /></td>';
                echo '<td><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" ';
                if (isset($rate['compound']) && $rate['compound'] == 'yes') {
                    echo 'checked="checked"';
                }
                echo ' /></td></tr>';
                ?>
<script type="text/javascript">
							/*<![CDATA[*/
								jQuery(function() {
									jQuery("#tax_country_<?php 
                echo esc_attr($i);
                ?>
").select2();
								});
							/*]]>*/
							</script><?php 
            }
        }
        ?>
				</tbody>

			</table>
			<div><a href="#" class="add button"><?php 
        _e('+ Add Tax Rule', 'jigoshop');
        ?>
</a></div>
		</div>

		<script type="text/javascript">
		/*<![CDATA[*/
			jQuery(function() {

				jQuery(document.body).on('click', 'tr.tax_rate .select_none', function(){
					jQuery(this).closest('td').find('select option').removeAttr("selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_all', function(){
					jQuery(this).closest('td').find('select option').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_us_states', function(){
					jQuery(this).closest('td').find('select optgroup[label="<?php 
        _e('United States', 'jigoshop');
        ?>
"] option').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});
				jQuery(document.body).on('change', 'tr.tax_rate .options select', function(e){
					jQuery(this).trigger("liszt:updated");
					jQuery(this).closest('td').find('label').text( jQuery(":selected", this).length + ' ' + '<?php 
        _e('countries/states selected', 'jigoshop');
        ?>
' );
				});
				jQuery(document.body).on('click', 'tr.tax_rate .select_europe', function(e){
					jQuery(this).closest('td').find('option[value="BE"],option[value="FR"],option[value="DE"],option[value="IT"],option[value="LU"],option[value="NL"],option[value="DK"],option[value="IE"],option[value="GR"],option[value="PT"],option[value="ES"],option[value="AT"],option[value="FI"],option[value="SE"],option[value="CY"],option[value="CZ"],option[value="EE"],option[value="HU"],option[value="LV"],option[value="LT"],option[value="MT"],option[value="PL"],option[value="SK"],option[value="SI"],option[value="RO"],option[value="BG"],option[value="IM"],option[value="GB"]').attr("selected","selected");
					jQuery(this).closest('td').find('select.tax_select2').trigger("change");
					return false;
				});

				jQuery(document.body).on('click', '#jigoshop_tax_rates a.add', function() {
					var size = jQuery('.tax_rate_rules tbody tr').size();
					jQuery('<tr class="tax_rate"> \
							<td><a href="#" class="remove button">&times;</a></td> \
							<td><select name="tax_classes[' + size + ']" > \
								<option value="*"><?php 
        _e('Standard Rate', 'jigoshop');
        ?>
</option> \
								<?php 
        $tax_classes = $_tax->get_tax_classes();
        if ($tax_classes) {
            foreach ($tax_classes as $class) {
                echo '<option value="' . sanitize_title($class) . '">' . $class . '</option>';
            }
        }
        ?>
 \
								</select></td> \
							<td><input type="text" name="tax_label[' + size + ']" placeholder="<?php 
        _e('Online Label', 'jigoshop');
        ?>
" size="10" /></td> \
							<td><select name="tax_country[' + size + '][]" id="tax_country_' + size +'" multiple="multiple" style="width:220px;"> \
									<?php 
        jigoshop_countries::country_dropdown_options('', '', true);
        ?>
</select> \
								<button class="select_none button"><?php 
        _e('None', 'jigoshop');
        ?>
</button> \
								<button class="button select_all"><?php 
        _e('All', 'jigoshop');
        ?>
</button> \
								<button class="button select_us_states"><?php 
        _e('US States', 'jigoshop');
        ?>
</button> \
								<button class="button select_europe"><?php 
        _e('EU States', 'jigoshop');
        ?>
</button></td> \
							<td><input type="text" name="tax_rate[' + size + ']" placeholder="<?php 
        _e('Rate (%)', 'jigoshop');
        ?>
" size="6" /> \
							<td><input type="checkbox" name="tax_shipping[' + size + ']" /></td> \
							<td><input type="checkbox" name="tax_compound[' + size + ']" /></td> \
							</tr>'
					).appendTo('#jigoshop_tax_rates .tax_rate_rules tbody');
					jQuery('#tax_country_' + size).select2();
					jQuery('#tax_country_' + size).addClass("tax_select2");
					return false;
				});
				jQuery(document.body).on('click', '#jigoshop_tax_rates a.remove', function(){
					var answer = confirm("<?php 
        _e('Delete this rule?', 'jigoshop');
        ?>
");
					if (answer) jQuery(this).parent().parent().remove();
					return false;
				});
			});
			/*]]>*/
			</script>
		<?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
 /**
  * Validate the checkout
  */
 public function validate_checkout()
 {
     if (jigoshop_cart::is_empty()) {
         jigoshop::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>', 'jigoshop'), home_url()));
     }
     // Process Discount Codes
     if (!empty($_POST['coupon_code'])) {
         $coupon = sanitize_title($_POST['coupon_code']);
         jigoshop_cart::add_discount($coupon);
     }
     foreach (jigoshop_cart::get_coupons() as $coupon) {
         jigoshop_cart::is_valid_coupon($coupon);
     }
     // Checkout fields
     $this->posted['shipping_method'] = '';
     $this->posted['shipping_service'] = '';
     if (isset($_POST['shipping_method'])) {
         $shipping_method = jigowatt_clean($_POST['shipping_method']);
         $shipping_data = explode(':', $shipping_method);
         $this->posted['shipping_method'] = $shipping_data[0];
         $this->posted['shipping_service'] = $shipping_data[1];
     }
     $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : '';
     $this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : '';
     $this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : '';
     $this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : '';
     $this->posted['create_account'] = isset($_POST['create_account']) ? jigowatt_clean($_POST['create_account']) : '';
     $this->posted['account_username'] = isset($_POST['account_username']) ? jigowatt_clean($_POST['account_username']) : '';
     $this->posted['account_password'] = isset($_POST['account_password']) ? jigowatt_clean($_POST['account_password']) : '';
     $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? jigowatt_clean($_POST['account_password_2']) : '';
     if (jigoshop_cart::get_total(false) == 0) {
         $this->posted['payment_method'] = 'no_payment';
     }
     // establish customer billing and shipping locations
     if (jigoshop_cart::ship_to_billing_address_only()) {
         $this->posted['shiptobilling'] = 'true';
     }
     $country = isset($_POST['billing_country']) ? jigowatt_clean($_POST['billing_country']) : '';
     $state = isset($_POST['billing_state']) ? jigowatt_clean($_POST['billing_state']) : '';
     $allowed_countries = Jigoshop_Base::get_options()->get('jigoshop_allowed_countries');
     if ($allowed_countries === 'specific') {
         $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries');
         if (!in_array($country, $specific_countries)) {
             jigoshop::add_error(__('Invalid billing country.', 'jigoshop'));
             return;
         }
     }
     if (jigoshop_countries::country_has_states($country)) {
         $states = jigoshop_countries::get_states($country);
         if (!in_array($state, array_keys($states))) {
             jigoshop::add_error(__('Invalid billing state.', 'jigoshop'));
             return;
         }
     }
     $postcode = isset($_POST['billing_postcode']) ? jigowatt_clean($_POST['billing_postcode']) : '';
     $ship_to_billing = Jigoshop_Base::get_options()->get('jigoshop_ship_to_billing_address_only') == 'yes';
     jigoshop_customer::set_location($country, $state, $postcode);
     if (Jigoshop_Base::get_options()->get('jigoshop_calc_shipping') == 'yes') {
         if ($ship_to_billing || !empty($_POST['shiptobilling'])) {
             jigoshop_customer::set_shipping_location($country, $state, $postcode);
         } else {
             $country = isset($_POST['shipping_country']) ? jigowatt_clean($_POST['shipping_country']) : '';
             $state = isset($_POST['shipping_state']) ? jigowatt_clean($_POST['shipping_state']) : '';
             $postcode = isset($_POST['shipping_postcode']) ? jigowatt_clean($_POST['shipping_postcode']) : '';
             if ($allowed_countries === 'specific') {
                 $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries');
                 if (!in_array($country, $specific_countries)) {
                     jigoshop::add_error(__('Invalid shipping country.', 'jigoshop'));
                     return;
                 }
             }
             if (jigoshop_countries::country_has_states($country)) {
                 $states = jigoshop_countries::get_states($country);
                 if (!in_array($state, array_keys($states))) {
                     jigoshop::add_error(__('Invalid shipping state.', 'jigoshop'));
                     return;
                 }
             }
             jigoshop_customer::set_shipping_location($country, $state, $postcode);
         }
     }
     // Billing Information
     foreach ($this->billing_fields as $field) {
         $field = apply_filters('jigoshop_billing_field', $field);
         $this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : '';
         // Format
         if (isset($field['format'])) {
             switch ($field['format']) {
                 case 'postcode':
                     $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                     break;
             }
         }
         // Required
         if ($field['name'] == 'billing_state' && jigoshop_customer::has_valid_shipping_state()) {
             $field['required'] = false;
         }
         if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
             jigoshop::add_error($field['label'] . __(' (billing) is a required field.', 'jigoshop'));
         }
         if ($field['name'] == 'billing_euvatno') {
             $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : '';
             $vatno = str_replace(' ', '', $vatno);
             $country = jigoshop_tax::get_customer_country();
             // strip any country code from the beginning of the number
             if (strpos($vatno, $country) === 0) {
                 $vatno = substr($vatno, strlen($country));
             }
             if ($vatno != '') {
                 $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/';
                 $httpRequest = curl_init();
                 curl_setopt($httpRequest, CURLOPT_FAILONERROR, true);
                 curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($httpRequest, CURLOPT_HEADER, false);
                 curl_setopt($httpRequest, CURLOPT_URL, $url);
                 $result = curl_exec($httpRequest);
                 curl_close($httpRequest);
                 if ($result === 'false') {
                     jigoshop_log('EU VAT validation error with URL: ' . $url);
                     jigoshop::add_error($field['label'] . __(' (billing) is not a valid VAT Number.  Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'jigoshop'));
                 } else {
                     $this->valid_euvatno = jigoshop_countries::get_base_country() != jigoshop_tax::get_customer_country() && jigoshop_countries::is_eu_country(jigoshop_tax::get_customer_country());
                 }
             }
         }
         // Validation
         if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
             switch ($field['validate']) {
                 case 'phone':
                     if (!jigoshop_validation::is_phone($this->posted[$field['name']])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid number.', 'jigoshop'));
                     }
                     break;
                 case 'email':
                     if (!jigoshop_validation::is_email($this->posted[$field['name']])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid email address.', 'jigoshop'));
                     }
                     break;
                 case 'postcode':
                     if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'jigoshop'));
                     } else {
                         $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']);
                     }
                     break;
             }
         }
     }
     // Shipping Information
     if (jigoshop_shipping::is_enabled() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) {
         foreach ($this->shipping_fields as $field) {
             $field = apply_filters('jigoshop_shipping_field', $field);
             if (isset($_POST[$field['name']])) {
                 $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]);
             } else {
                 $this->posted[$field['name']] = '';
             }
             // Format
             if (isset($field['format'])) {
                 switch ($field['format']) {
                     case 'postcode':
                         $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                         break;
                 }
             }
             // Required
             if ($field['name'] == 'shipping_state' && jigoshop_customer::has_valid_shipping_state()) {
                 $field['required'] = false;
             }
             if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
                 jigoshop::add_error($field['label'] . __(' (shipping) is a required field.', 'jigoshop'));
             }
             // Validation
             if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
                 switch ($field['validate']) {
                     case 'postcode':
                         if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $country)) {
                             jigoshop::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'jigoshop'));
                         } else {
                             $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $country);
                         }
                         break;
                 }
             }
         }
     }
     if ($this->must_register && empty($this->posted['create_account'])) {
         jigoshop::add_error(__('Sorry, you must agree to creating an account', 'jigoshop'));
     }
     if ($this->must_register || empty($user_id) && $this->posted['create_account']) {
         if (!$this->show_signup) {
             jigoshop::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'jigoshop'));
         }
         if (empty($this->posted['account_username'])) {
             jigoshop::add_error(__('Please enter an account username.', 'jigoshop'));
         }
         if (empty($this->posted['account_password'])) {
             jigoshop::add_error(__('Please enter an account password.', 'jigoshop'));
         }
         if ($this->posted['account_password_2'] !== $this->posted['account_password']) {
             jigoshop::add_error(__('Passwords do not match.', 'jigoshop'));
         }
         // Check the username
         if (!validate_username($this->posted['account_username'])) {
             jigoshop::add_error(__('Invalid email/username.', 'jigoshop'));
         } elseif (username_exists($this->posted['account_username'])) {
             jigoshop::add_error(__('An account is already registered with that username. Please choose another.', 'jigoshop'));
         }
         // Check the e-mail address
         if (email_exists($this->posted['billing_email'])) {
             jigoshop::add_error(__('An account is already registered with your email address. Please login.', 'jigoshop'));
         }
     }
     // Terms
     if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && jigoshop_get_page_id('terms') > 0) {
         jigoshop::add_error(__('You must accept our Terms &amp; Conditions.', 'jigoshop'));
     }
     if (jigoshop_cart::needs_shipping()) {
         // Shipping Method
         $available_methods = jigoshop_shipping::get_available_shipping_methods();
         if (!isset($available_methods[$this->posted['shipping_method']])) {
             jigoshop::add_error(__('Invalid shipping method.', 'jigoshop'));
         }
     }
 }
/**
 * Admin fields
 * 
 * Loops though the jigoshop options array and outputs each field.
 *
 * @since 		1.0
 * @usedby 		jigoshop_settings()
 *
 * @param 		array $options List of options to go through and save
 */
function jigoshop_admin_fields($options) {
	?>
	<div id="tabs-wrap">
		<p class="submit"><input name="save" type="submit" value="<?php _e('Save changes','jigoshop') ?>" /></p>
		<?php
		    $counter = 1;
		    echo '<ul class="tabs">';
		    foreach ($options as $value) {
				if ( 'tab' == $value['type'] ) :
		            echo '<li><a href="#'.$value['type'].$counter.'">'.$value['tabname'].'</a></li>'. "\n";
		            $counter = $counter + 1;
				endif;
		    }
		    echo '</ul>';
		    $counter = 1;
		    foreach ($options as $value) :
		        switch($value['type']) :
					case 'string':
						?>
						<tr>
							<td class="titledesc"><?php echo $value['name']; ?></td>
							<td class="forminp"><?php echo $value['desc']; ?></td>
						</tr>
						<?php
					break;
		            case 'tab':
		                echo '<div id="'.$value['type'].$counter.'" class="panel">';
		                echo '<table class="widefat fixed" style="width:850px; margin-bottom:20px;">'. "\n\n";
		            break;
		            case 'title':
		            	?><thead><tr><th scope="col" width="200px"><?php echo $value['name'] ?></th><th scope="col" class="desc"><?php if (isset($value['desc'])) echo $value['desc'] ?>&nbsp;</th></tr></thead><?php
		            break;
		            case 'text':
		            	?><tr>
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp"><input name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" type="<?php echo $value['type'] ?>" style="<?php echo $value['css'] ?>" value="<?php if ( get_option( $value['id']) !== false && get_option( $value['id']) !== null ) echo get_option( $value['id'] ); else echo $value['std'] ?>" /><br /><small><?php echo $value['desc'] ?></small></td>
		                </tr><?php
		            break;
		            case 'select':
		            	?><tr>
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp"><select name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>">
		                        <?php
		                        foreach ($value['options'] as $key => $val) {
		                        ?>
		                            <option value="<?php echo $key ?>" <?php if (get_option($value['id']) == $key) { ?> selected="selected" <?php } ?>><?php echo ucfirst($val) ?></option>
		                        <?php
		                        }
		                        ?>
		                       </select><br /><small><?php echo $value['desc'] ?></small>
		                    </td>
		                </tr><?php
		            break;
		            case 'textarea':
		            	?><tr>
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp">
		                        <textarea <?php if ( isset($value['args']) ) echo $value['args'] . ' '; ?>name="<?php echo $value['id'] ?>" id="<?php echo $value['id'] ?>" style="<?php echo $value['css'] ?>"><?php if (get_option($value['id'])) echo stripslashes(get_option($value['id'])); else echo $value['std']; ?></textarea>
		                        <br /><small><?php echo $value['desc'] ?></small>
		                    </td>
		                </tr><?php
		            break;
		            case 'tabend':
						echo '</table></div>';
		                $counter = $counter + 1;
		            break;
		            case 'single_select_page' :
		            	$page_setting = (int) get_option($value['id']);
		            	
		            	$args = array( 'name'	=> $value['id'],
		            				   'id'		=> $value['id']. '" style="width: 200px;',
		            				   'sort_column' 	=> 'menu_order',
		            				   'sort_order'		=> 'ASC',
		            				   'selected'		=> $page_setting);
		            	
		            	if( isset($value['args']) ) $args = wp_parse_args($value['args'], $args);
		            	
		            	?><tr class="single_select_page">
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp">
					        	<?php wp_dropdown_pages($args); ?>  
					        	<br /><small><?php echo $value['desc'] ?></small>        
					        </td>
		               	</tr><?php	
		            break;
		            case 'single_select_country' :
		            	$countries = jigoshop_countries::$countries;
		            	$country_setting = (string) get_option($value['id']);
		            	if (strstr($country_setting, ':')) :
		            		$country = current(explode(':', $country_setting));
		            		$state = end(explode(':', $country_setting));
		            	else :
		            		$country = $country_setting;
		            		$state = '*';
		            	endif;
		            	?><tr class="multi_select_countries">
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp"><select name="<?php echo $value['id'] ?>" title="Country" style="width: 150px;">	
					        	<?php echo jigoshop_countries::country_dropdown_options($country, $state); ?>          
					        </select>
		               		</td>
		               	</tr><?php	
		            break;
		            case 'multi_select_countries' :
		            	$countries = jigoshop_countries::$countries;
		            	asort($countries);
		            	$selections = (array) get_option($value['id']);
		            	?><tr class="multi_select_countries">
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp">
		                    	<div class="multi_select_countries"><ul><?php
			            			if ($countries) foreach ($countries as $key=>$val) :
		                    			                    			
			            				echo '<li><label><input type="checkbox" name="'. $value['id'] .'[]" value="'. $key .'" ';
			            				if (in_array($key, $selections)) echo 'checked="checked"';
			            				echo ' />'. $val .'</label></li>';
		 
		                    		endforeach;
		               			?></ul></div>
		               		</td>
		               	</tr><?php		            	
		            break;
		            case 'coupons' :
		            	$coupons = new jigoshop_coupons();
		            	$coupon_codes = $coupons->get_coupons();
		            	?><tr>
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp" id="coupon_codes">
		                    	<table class="coupon_rows" cellspacing="0">
			                    	<thead>
			                    		<tr>
			                    			<th><?php _e('Coupon Code', 'jigoshop'); ?></th>
			                    			<th><?php _e('Coupon Type', 'jigoshop'); ?></th>
			                    			<th><?php _e('Coupon Amount', 'jigoshop'); ?></th>
			                    			<th><?php _e('Product ids', 'jigoshop'); ?></th>
			                    			<th><?php _e('Individual use', 'jigoshop'); ?></th>
			                    			<th><?php _e('Delete', 'jigoshop'); ?></th>
			                    		</tr>
			                    	</thead>
			                    	<tbody>
			                    	<?php
			                    	$i = -1;
			                    	if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes)>0) foreach( $coupon_codes as $coupon ) : $i++;
			                    		echo '<tr class="coupon_row"><td><input type="text" value="'.$coupon['code'].'" name="coupon_code['.$i.']" title="'.__('Coupon Code', 'jigoshop').'" placeholder="'.__('Coupon Code', 'jigoshop').'" class="text" /></td><td><select name="coupon_type['.$i.']" title="Coupon Type">';
			                    		
			                    		$discount_types = array(
			                    			'fixed_cart' 	=> __('Cart Discount', 'jigoshop'),
			                    			'percent' 		=> __('Cart % Discount', 'jigoshop'),
			                    			'fixed_product'	=> __('Product Discount', 'jigoshop')
			                    		);
			                    		
			                    		foreach ($discount_types as $type => $label) :
			                    			$selected = ($coupon['type']==$type) ? 'selected="selected"' : '';
			                    			echo '<option value="'.$type.'" '.$selected.'>'.$label.'</option>';
			                    		endforeach;
			                    		
			                    		echo '</select></td><td><input type="text" value="'.$coupon['amount'].'" name="coupon_amount['.$i.']" title="'.__('Coupon Amount', 'jigoshop').'" placeholder="'.__('Coupon Amount', 'jigoshop').'" class="text" /></td><td><input type="text" value="'.implode(', ', $coupon['products']).'" name="product_ids['.$i.']" placeholder="'.__('1, 2, 3', 'jigoshop').'" class="text" /></td><td><label><input type="checkbox" name="individual['.$i.']" ';
					                    
					                    if (isset($coupon['individual_use']) && $coupon['individual_use']=='yes') echo 'checked="checked"';
					                    
					                    echo ' /> '.__('Individual use only', 'jigoshop').'</label></td><td><a href="#" class="remove button">&times;</a></td></tr>';
			                    	endforeach;
			                    	?>
			                    	</tbody>
		                        </table>
		                        <p><a href="#" class="add button"><?php _e('+ Add Coupon', 'jigoshop'); ?></a></p>
		                    </td>
		                </tr>
		                <script type="text/javascript">
						/* <![CDATA[ */
							jQuery(function() {
								jQuery('#coupon_codes a.add').live('click', function(){
									var size = jQuery('#coupon_codes table.coupon_rows tbody .coupon_row').size();
									
									// Make sure tbody exists
									var tbody_size = jQuery('#coupon_codes table.coupon_rows tbody').size();
									if (tbody_size==0) jQuery('#coupon_codes table.coupon_rows').append('<tbody></tbody>');
									
									// Add the row
									jQuery('<tr class="coupon_row">\
										<td><input type="text" value="" name="coupon_code[' + size + ']" title="<?php _e('Coupon Code', 'jigoshop'); ?>" placeholder="<?php _e('Coupon Code', 'jigoshop'); ?>" class="text" /></td>\
										<td><select name="coupon_type[' + size + ']" title="Coupon Type">\
			                    			<option value="percent"><?php _e('% Discount', 'jigoshop'); ?></option>\
			                    			<option value="fixed_product"><?php _e('Product Discount', 'jigoshop');?></option>\
			                    			<option value="fixed_cart"><?php _e('Cart Discount', 'jigoshop'); ?></option>\
			                    		</select></td>\
			                    		<td><input type="text" value="" name="coupon_amount[' + size + ']" title="<?php _e('Coupon Amount', 'jigoshop'); ?>" placeholder="<?php _e('Coupon Amount', 'jigoshop'); ?>" class="text" /></td>\
			                    		<td><input type="text" value="" name="product_ids[' + size + ']" placeholder="<?php _e('1, 2, 3', 'jigoshop'); ?>" class="text" /></td>\
			                    		<td><label><input type="checkbox" name="individual[' + size + ']" /> <?php _e('Individual use only', 'jigoshop'); ?></label></td>\
			                    		<td><a href="#" class="remove button">&times;</a></td></tr>').appendTo('#coupon_codes table.coupon_rows tbody');
									return false;
								});
								jQuery('#coupon_codes a.remove').live('click', function(){
									var answer = confirm("<?php _e('Delete this coupon?', 'jigoshop'); ?>")
									if (answer) {
										jQuery('input', jQuery(this).parent().parent()).val('');
										jQuery(this).parent().parent().hide();
									}
									return false;
								});
							});						
						/* ]]> */
						</script>
		                <?php
		            break;
		            case 'tax_rates' :
		            	$_tax = new jigoshop_tax();
		            	$tax_classes = $_tax->get_tax_classes();
		            	$tax_rates = get_option('jigoshop_tax_rates');
		            	?><tr>
		                    <td class="titledesc"><?php if ($value['tip']) { ?><a href="#" tip="<?php echo $value['tip'] ?>" class="tips" tabindex="99"></a><?php } ?><?php echo $value['name'] ?>:</td>
		                    <td class="forminp" id="tax_rates">
		                    	<div class="taxrows">
			                    	<?php
			                    	$i = -1;
			                    	if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates)>0) foreach( $tax_rates as $rate ) : $i++;
			                    		echo '<p class="taxrow"><select name="tax_class['.$i.']" title="Tax Class"><option value="">'.__('Standard Rate', 'jigoshop').'</option>';
			                    		
			                    		if ($tax_classes) foreach ($tax_classes as $class) :
					                        echo '<option value="'.sanitize_title($class).'"';
					                        
					                        if ($rate['class']==sanitize_title($class)) echo 'selected="selected"';
					                        
					                        echo '>'.$class.'</option>';
					                    endforeach;
					                    
					                    echo '</select><select name="tax_country['.$i.']" title="Country">';	
					                        		
					                    jigoshop_countries::country_dropdown_options($rate['country'], $rate['state']);
					                    
					                    echo '</select><input type="text" class="text" value="'.$rate['rate'].'" name="tax_rate['.$i.']" title="'.__('Rate', 'jigoshop').'" placeholder="'.__('Rate', 'jigoshop').'" maxlength="8" />% <label><input type="checkbox" name="tax_shipping['.$i.']" ';
					                    
					                    if (isset($rate['shipping']) && $rate['shipping']=='yes') echo 'checked="checked"';
					                    
					                    echo ' /> '.__('Apply to shipping', 'jigoshop').'</label><a href="#" class="remove button">&times;</a></p>';
			                    	endforeach;
			                    	?>
		                        </div>
		                        <p><a href="#" class="add button"><?php _e('+ Add Tax Rule', 'jigoshop'); ?></a></p>
		                    </td>
		                </tr>
		                <script type="text/javascript">
						/* <![CDATA[ */
							jQuery(function() {
								jQuery('#tax_rates a.add').live('click', function(){
									var size = jQuery('.taxrows .taxrow').size();
									
									// Add the row
									jQuery('<p class="taxrow"> \
				                        <select name="tax_class[' + size + ']" title="Tax Class"> \
				                        	<option value=""><?php _e('Standard Rate', 'jigoshop'); ?></option><?php
				                        		$tax_classes = $_tax->get_tax_classes();
				                        		if ($tax_classes) foreach ($tax_classes as $class) :
				                        			echo '<option value="'.sanitize_title($class).'">'.$class.'</option>';
				                        		endforeach;
				                        	?></select><select name="tax_country[' + size + ']" title="Country"><?php
				                        		jigoshop_countries::country_dropdown_options('','',true);
				                        	?></select><input type="text" class="text" name="tax_rate[' + size + ']" title="<?php _e('Rate', 'jigoshop'); ?>" placeholder="<?php _e('Rate', 'jigoshop'); ?>" maxlength="8" />%\
				                        	<label><input type="checkbox" name="tax_shipping[' + size + ']" /> <?php _e('Apply to shipping', 'jigoshop'); ?></label>\
				                        	<a href="#" class="remove button">&times;</a>\
			                        </p>').appendTo('#tax_rates div.taxrows');
									return false;
								});
								jQuery('#tax_rates a.remove').live('click', function(){
									var answer = confirm("<?php _e('Delete this rule?', 'jigoshop'); ?>");
									if (answer) {
										jQuery('input', jQuery(this).parent()).val('');
										jQuery(this).parent().hide();
									}
									return false;
								});
							});						
						/* ]]> */
						</script>
		                <?php
		            break;
		            case "shipping_options" :
		            
		            	foreach (jigoshop_shipping::$shipping_methods as $method) :
		            		
		            		$method->admin_options();
		            		
		            	endforeach;  
		            	          
		            break;
		            case "gateway_options" :
		            
		            	foreach (jigoshop_payment_gateways::payment_gateways() as $gateway) :
		            		
		            		$gateway->admin_options();
		            		
		            	endforeach; 
		            	           
		            break;
		        endswitch;
		    endforeach;
		?>
		<p class="submit"><input name="save" type="submit" value="<?php _e('Save changes','jigoshop') ?>" /></p>
	</div>
	<script type="text/javascript">
	jQuery(function() {
	    // Tabs
		jQuery('ul.tabs').show();
		jQuery('ul.tabs li:first').addClass('active');
		jQuery('div.panel:not(div.panel:first)').hide();
		jQuery('ul.tabs a').click(function(){
			jQuery('ul.tabs li').removeClass('active');
			jQuery(this).parent().addClass('active');
			jQuery('div.panel').hide();
			jQuery( jQuery(this).attr('href') ).show();
			
			jQuery.cookie('jigoshop_settings_tab_index', jQuery(this).parent().index('ul.tabs li'))

			return false;
		});
		
		<?php if (isset($_COOKIE['jigoshop_settings_tab_index']) && $_COOKIE['jigoshop_settings_tab_index'] > 0) : ?>
			
			jQuery('ul.tabs li:eq(<?php echo $_COOKIE['jigoshop_settings_tab_index']; ?>) a').click();
			
		<?php endif; ?>
		
		// Countries
		jQuery('select#jigoshop_allowed_countries').change(function(){
			if (jQuery(this).val()=="specific") {
				jQuery(this).parent().parent().next('tr.multi_select_countries').show();
			} else {
				jQuery(this).parent().parent().next('tr.multi_select_countries').hide();
			}
		}).change();
		
	});
	</script>
	<?php
}
示例#10
0
 public function __construct($id)
 {
     $this->id = $id;
     $meta = get_user_meta($id);
     if (isset($meta['billing_first_name'])) {
         $this->billing_first_name = $meta['billing_first_name'][0];
     }
     if (isset($meta['billing_last_name'])) {
         $this->billing_last_name = $meta['billing_last_name'][0];
     }
     if (isset($meta['billing_company'])) {
         $this->billing_company = $meta['billing_company'][0];
     }
     if (isset($meta['billing_euvatno'])) {
         $this->billing_euvatno = $meta['billing_euvatno'][0];
     }
     if (isset($meta['billing_address_1'])) {
         $this->billing_address_1 = $meta['billing_address_1'][0];
     }
     if (isset($meta['billing_address_2'])) {
         $this->billing_address_2 = $meta['billing_address_2'][0];
     }
     if (isset($meta['billing_city'])) {
         $this->billing_city = $meta['billing_city'][0];
     }
     if (isset($meta['billing_state'])) {
         $this->billing_state = $meta['billing_state'][0];
     }
     if (isset($meta['billing_postcode'])) {
         $this->billing_postcode = $meta['billing_postcode'][0];
     }
     if (isset($meta['billing_country'])) {
         $country = $meta['billing_country'][0];
         $country = jigoshop_countries::has_country($country) ? $country : jigoshop_countries::get_base_country();
         $this->billing_country = $country;
     }
     if (isset($meta['billing_email'])) {
         $this->billing_email = $meta['billing_email'][0];
     }
     if (isset($meta['billing_first_name'])) {
         $this->billing_phone = $meta['billing_phone'][0];
     }
     if (isset($meta['shipping_first_name'])) {
         $this->shipping_first_name = $meta['shipping_first_name'][0];
     }
     if (isset($meta['shipping_last_name'])) {
         $this->shipping_last_name = $meta['shipping_last_name'][0];
     }
     if (isset($meta['shipping_company'])) {
         $this->shipping_company = $meta['shipping_company'][0];
     }
     if (isset($meta['shipping_address_1'])) {
         $this->shipping_address_1 = $meta['shipping_address_1'][0];
     }
     if (isset($meta['shipping_address_2'])) {
         $this->shipping_address_2 = $meta['shipping_address_2'][0];
     }
     if (isset($meta['shipping_city'])) {
         $this->shipping_city = $meta['shipping_city'][0];
     }
     if (isset($meta['shipping_state'])) {
         $this->shipping_state = $meta['shipping_state'][0];
     }
     if (isset($meta['shipping_postcode'])) {
         $this->shipping_postcode = $meta['shipping_postcode'][0];
     }
     if (isset($meta['shipping_country'])) {
         $country = $meta['shipping_country'][0];
         $country = jigoshop_countries::has_country($country) ? $country : jigoshop_countries::get_base_country();
         $this->shipping_country = $country;
     }
 }
示例#11
0
 /** Populates an order from the loaded post data */
 public function populate($result)
 {
     // Standard post data
     $this->id = $result->ID;
     $this->order_date = $result->post_date;
     $this->modified_date = $result->post_modified;
     $this->customer_note = $result->post_excerpt;
     // Custom field data
     $this->order_key = (string) get_post_meta($this->id, 'order_key', true);
     $this->user_id = (int) get_post_meta($this->id, 'customer_user', true);
     $this->items = (array) get_post_meta($this->id, 'order_items', true);
     $this->order_data = (array) maybe_unserialize(get_post_meta($this->id, 'order_data', true));
     $this->billing_first_name = (string) $this->_fetch('billing_first_name');
     $this->billing_last_name = (string) $this->_fetch('billing_last_name');
     $this->billing_company = (string) $this->_fetch('billing_company');
     $this->billing_euvatno = (string) $this->_fetch('billing_euvatno');
     $this->billing_address_1 = (string) $this->_fetch(array('billing_address_1', 'billing_address'));
     $this->billing_address_2 = (string) $this->_fetch('billing_address_2');
     $this->billing_city = (string) $this->_fetch('billing_city');
     $this->billing_postcode = (string) $this->_fetch('billing_postcode');
     $this->billing_country = (string) $this->_fetch('billing_country');
     $this->billing_state = (string) $this->_fetch('billing_state');
     $this->billing_email = (string) $this->_fetch('billing_email');
     $this->billing_phone = (string) $this->_fetch('billing_phone');
     $this->shipping_first_name = (string) $this->_fetch('shipping_first_name');
     $this->shipping_last_name = (string) $this->_fetch('shipping_last_name');
     $this->shipping_company = (string) $this->_fetch('shipping_company');
     $this->shipping_address_1 = (string) $this->_fetch(array('shipping_address_1', 'shipping_address'));
     $this->shipping_address_2 = (string) $this->_fetch('shipping_address_2');
     $this->shipping_city = (string) $this->_fetch('shipping_city');
     $this->shipping_postcode = (string) $this->_fetch('shipping_postcode');
     $this->shipping_country = (string) $this->_fetch('shipping_country');
     $this->shipping_state = (string) $this->_fetch('shipping_state');
     $this->shipping_method = (string) $this->_fetch('shipping_method');
     $this->shipping_service = (string) $this->_fetch('shipping_service');
     $this->payment_method = (string) $this->_fetch('payment_method');
     $this->payment_method_title = (string) $this->_fetch('payment_method_title');
     $this->order_subtotal = (string) $this->_fetch('order_subtotal');
     $this->order_discount_subtotal = (string) $this->_fetch('order_discount_subtotal');
     $this->order_shipping = (string) $this->_fetch('order_shipping');
     $this->order_discount = (string) $this->_fetch('order_discount');
     $this->order_discount_coupons = $this->_fetch('order_discount_coupons');
     //array
     $this->order_tax = $this->get_order_tax_array('order_tax');
     $this->order_shipping_tax = (string) $this->_fetch('order_shipping_tax');
     $this->order_total = (string) $this->_fetch('order_total');
     // array
     $this->order_total_prices_per_tax_class_ex_tax = $this->_fetch('order_total_prices_per_tax_class_ex_tax');
     // Formatted Addresses
     $country = $this->billing_country && jigoshop_countries::has_country($this->billing_country) ? jigoshop_countries::get_country($this->billing_country) : $this->billing_country;
     $address = array_map('trim', array($this->billing_address_1, $this->billing_address_2, $this->billing_city, $this->billing_state, $country, $this->billing_postcode));
     $this->formatted_billing_address = implode(', ', array_filter($address));
     if ($this->shipping_address_1) {
         $country = $this->shipping_country && jigoshop_countries::has_country($this->shipping_country) ? jigoshop_countries::get_country($this->shipping_country) : $this->shipping_country;
         $address = array_map('trim', array($this->shipping_address_1, $this->shipping_address_2, $this->shipping_city, $this->shipping_state, $country, $this->shipping_postcode));
         $this->formatted_shipping_address = implode(', ', array_filter($address));
     }
     // Taxonomy data
     $this->status = 'new';
     $terms = get_the_terms($this->id, 'shop_order_status');
     if (!is_wp_error($terms) && $terms) {
         $term = current($terms);
         $this->status = $term->slug;
     }
 }
示例#12
0
function jigoshop_cart( $atts ) {
	
	$errors = array();
	
	// Process Discount Codes
	if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) :
	
		$coupon_code = stripslashes(trim($_POST['coupon_code']));
		jigoshop_cart::add_discount($coupon_code);

	// Remove from cart
	elseif ( isset($_GET['remove_item']) && $_GET['remove_item'] > 0  && jigoshop::verify_nonce('cart', '_GET')) :
	
		jigoshop_cart::set_quantity( $_GET['remove_item'], 0 );
		
		jigoshop::add_message( __('Cart updated.', 'jigoshop') );
	
	// Update Cart
	elseif (isset($_POST['update_cart']) && $_POST['update_cart']  && jigoshop::verify_nonce('cart')) :
		
		$cart_totals = $_POST['cart'];
		
		if (sizeof(jigoshop_cart::$cart_contents)>0) : 
			foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
				
				if (isset($cart_totals[$item_id]['qty'])) jigoshop_cart::set_quantity( $item_id, $cart_totals[$item_id]['qty'] );
				
			endforeach;
		endif;
		
		jigoshop::add_message( __('Cart updated.', 'jigoshop') );
	
	// Update Shipping
	elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) :

		unset($_SESSION['_chosen_method_id']);
		$country 	= $_POST['calc_shipping_country'];
		$state 	= $_POST['calc_shipping_state'];
		
		$postcode 	= $_POST['calc_shipping_postcode'];
		
		if ($postcode && !jigoshop_validation::is_postcode( $postcode, $country )) : 
			jigoshop::add_error( __('Please enter a valid postcode/ZIP.','jigoshop') ); 
			$postcode = '';
		elseif ($postcode) :
			$postcode = jigoshop_validation::format_postcode( $postcode, $country );
		endif;
		
		if ($country) :
		
			// Update customer location
			jigoshop_customer::set_location( $country, $state, $postcode );
			jigoshop_customer::set_shipping_location( $country, $state, $postcode );
			
			// Re-calc price
			jigoshop_cart::calculate_totals();
			
			jigoshop::add_message(  __('Shipping costs updated.', 'jigoshop') );
		
		else :
		
			jigoshop_customer::set_shipping_location( '', '', '' );
			
			jigoshop::add_message(  __('Shipping costs updated.', 'jigoshop') );
			
		endif;
			
	endif;
	
	$result = jigoshop_cart::check_cart_item_stock();
	if (is_wp_error($result)) :
		jigoshop::add_error( $result->get_error_message() );
	endif;
	
	jigoshop::show_messages();
	
	if (sizeof(jigoshop_cart::$cart_contents)==0) :
		echo '<p>'.__('Your cart is empty.', 'jigoshop').'</p>';
		return;
	endif;
	
	?>
	<form action="<?php echo jigoshop_cart::get_cart_url(); ?>" method="post">
	<table class="shop_table cart" cellspacing="0">
		<thead>
			<tr>
				<th class="product-remove"></th>
				<th class="product-thumbnail"></th>
				<th class="product-name"><span class="nobr"><?php _e('Product Name', 'jigoshop'); ?></span></th>
				<th class="product-price"><span class="nobr"><?php _e('Unit Price', 'jigoshop'); ?></span></th>
				<th class="product-quantity"><?php _e('Quantity', 'jigoshop'); ?></th>
				<th class="product-subtotal"><?php _e('Price', 'jigoshop'); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			if (sizeof(jigoshop_cart::$cart_contents)>0) : 
				foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
					$_product = $values['data'];
					if ($_product->exists() && $values['quantity']>0) :
						echo '
							<tr>
								<td class="product-remove"><a href="'.jigoshop_cart::get_remove_url($item_id).'" class="remove" title="Remove this item">&times;</a></td>
								<td class="product-thumbnail"><a href="'.get_permalink($item_id).'">';
						
						if (has_post_thumbnail($item_id)) echo get_the_post_thumbnail($item_id, 'shop_tiny'); 
						else echo '<img src="'.jigoshop::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.jigoshop::get_var('shop_tiny_w').'" height="'.jigoshop::get_var('shop_tiny_h').'" />'; 
							
						echo '	</a></td>
								<td class="product-name"><a href="'.get_permalink($item_id).'">' . apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product) . '</a></td>
								<td class="product-price">'.jigoshop_price($_product->get_price()).'</td>
								<td class="product-quantity"><div class="quantity"><input name="cart['.$item_id.'][qty]" value="'.$values['quantity'].'" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td>
								<td class="product-subtotal">'.jigoshop_price($_product->get_price()*$values['quantity']).'</td>
							</tr>';
					endif;
				endforeach; 
			endif;
			
			do_action( 'jigoshop_shop_table_cart' );
			?>
			<tr>
				<td colspan="6" class="actions">
					<div class="coupon">
						<label for="coupon_code"><?php _e('Coupon', 'jigoshop'); ?>:</label> <input name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'jigoshop'); ?>" />
					</div>
					<?php jigoshop::nonce_field('cart') ?>
					<input type="submit" class="button" name="update_cart" value="<?php _e('Update Shopping Cart', 'jigoshop'); ?>" /> <a href="<?php echo jigoshop_cart::get_checkout_url(); ?>" class="checkout-button button-alt"><?php _e('Proceed to Checkout &rarr;', 'jigoshop'); ?></a>
				</td>
			</tr>
		</tbody>
	</table>
	</form>
	<div class="cart-collaterals">
		
		<?php do_action('cart-collaterals'); ?>

		<div class="cart_totals">
		<?php
		// Hide totals if customer has set location and there are no methods going there
		$available_methods = jigoshop_shipping::get_available_shipping_methods();
		if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::$enabled ) : 
			?>
			<h2><?php _e('Cart Totals', 'jigoshop'); ?></h2>
			<table cellspacing="0" cellpadding="0">
				<tbody>
					<tr>
						<th><?php _e('Subtotal', 'jigoshop'); ?></th>
						<td><?php echo jigoshop_cart::get_cart_subtotal(); ?></td>
					</tr>
					
					<?php if (jigoshop_cart::get_cart_shipping_total()) : ?><tr>
						<th><?php _e('Shipping', 'jigoshop'); ?> <small><?php echo jigoshop_countries::shipping_to_prefix().' '.jigoshop_countries::$countries[ jigoshop_customer::get_shipping_country() ]; ?></small></th>
						<td><?php echo jigoshop_cart::get_cart_shipping_total(); ?> <small><?php echo jigoshop_cart::get_cart_shipping_title(); ?></small></td>
					</tr><?php endif; ?>
					<?php if (jigoshop_cart::get_cart_tax()) : ?><tr>
						<th><?php _e('Tax', 'jigoshop'); ?> <?php if (jigoshop_customer::is_customer_outside_base()) : ?><small><?php echo sprintf(__('estimated for %s', 'jigoshop'), jigoshop_countries::estimated_for_prefix() . jigoshop_countries::$countries[ jigoshop_countries::get_base_country() ] ); ?></small><?php endif; ?></th>
						<td><?php 
							echo jigoshop_cart::get_cart_tax(); 
						?></td>
					</tr><?php endif; ?>
					
					<?php if (jigoshop_cart::get_total_discount()) : ?><tr class="discount">
						<th><?php _e('Discount', 'jigoshop'); ?></th>
						<td>-<?php echo jigoshop_cart::get_total_discount(); ?></td>
					</tr><?php endif; ?>
					<tr>
						<th><strong><?php _e('Total', 'jigoshop'); ?></strong></th>
						<td><strong><?php echo jigoshop_cart::get_total(); ?></strong></td>
					</tr>
				</tbody>
			</table>

			<?php
			else :
				echo '<p>'.__('Sorry, it seems that there are no available shipping methods to your location. Please contact us if you require assistance or wish to make alternate arrangements.', 'jigoshop').'</p>';
			endif;
		?>
		</div>
		
		<?php jigoshop_shipping_calculator(); ?>
		
	</div>
	<?php		
}
示例#13
0
 /**
  *  Admin Notices for conditions under which FuturePay is available on a Shop
  */
 public function futurepay_notices()
 {
     if ($this->enabled == 'no') {
         return;
     }
     if (!in_array(Jigoshop_Base::get_options()->get('jigoshop_currency'), $this->allowed_currency)) {
         echo '<div class="error"><p>' . sprintf(__('The FuturePay gateway accepts payments in currencies of %s.  Your current currency is %s.  FuturePay won\'t work until you change the Jigoshop currency to an accepted one.  FuturePay is currently disabled on the Payment Gateways settings tab.', 'jigoshop'), implode(', ', $this->allowed_currency), Jigoshop_Base::get_options()->get('jigoshop_currency')) . '</p></div>';
         Jigoshop_Base::get_options()->set('jigoshop_futurepay_enabled', 'no');
     }
     if (!in_array($this->shop_base_country, $this->merchant_countries)) {
         $country_list = array();
         foreach ($this->merchant_countries as $this_country) {
             $country_list[] = jigoshop_countries::get_country($this_country);
         }
         echo '<div class="error"><p>' . sprintf(__('The FuturePay gateway is available to merchants from: %s.  Your country is: %s.  FuturePay won\'t work until you change the Jigoshop Shop Base country to an accepted one.  FuturePay is currently disabled on the Payment Gateways settings tab.', 'jigoshop'), implode(', ', $country_list), jigoshop_countries::get_base_country()) . '</p></div>';
         Jigoshop_Base::get_options()->set('jigoshop_futurepay_enabled', 'no');
     }
 }
示例#14
0
function my_cart($atts)
{
    $errors = array();
    unset(jigoshop_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) {
        $coupon_code = stripslashes(trim($_POST['coupon_code']));
        jigoshop_cart::add_discount($coupon_code);
        // Update Shipping
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) {
        unset(jigoshop_session::instance()->chosen_shipping_method_id);
        $country = $_POST['calc_shipping_country'];
        $state = $_POST['calc_shipping_state'];
        $postcode = $_POST['calc_shipping_postcode'];
        if ($postcode && !jigoshop_validation::is_postcode($postcode, $country)) {
            jigoshop::add_error(__('Please enter a valid postcode/ZIP.', 'jigoshop'));
            $postcode = '';
        } elseif ($postcode) {
            $postcode = jigoshop_validation::format_postcode($postcode, $country);
        }
        if ($country) {
            // Update customer location
            jigoshop_customer::set_location($country, $state, $postcode);
            jigoshop_customer::set_shipping_location($country, $state, $postcode);
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        } else {
            jigoshop_customer::set_shipping_location('', '', '');
            jigoshop::add_message(__('Shipping costs updated.', 'jigoshop'));
        }
    } elseif (isset($_POST['shipping_rates'])) {
        $rates_params = explode(":", $_POST['shipping_rates']);
        $available_methods = jigoshop_shipping::get_available_shipping_methods();
        $shipping_method = $available_methods[$rates_params[0]];
        if ($rates_params[1] != NULL) {
            jigoshop_session::instance()->selected_rate_id = $rates_params[1];
        }
        $shipping_method->choose();
        // choses the method selected by user.
    }
    // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results. It will happen twice for coupon.
    jigoshop_cart::calculate_totals();
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    jigoshop::show_messages();
    if (sizeof(jigoshop_cart::$cart_contents) == 0) {
        echo '<p>' . __('Your cart is empty.', 'jigoshop') . '</p>';
        ?>
<p><a href="<?php 
        echo esc_url(jigoshop_cart::get_shop_url());
        ?>
" class="button"><?php 
        _e('&larr; Return to Shop', 'jigoshop');
        ?>
</a></p><?php 
        return;
    }
    ?>
    <form action="<?php 
    echo esc_url(jigoshop_cart::get_cart_url());
    ?>
" method="post">
        <table class="shop_table cart" cellspacing="0" id="shop-cart">
            <thead>
                <tr>
                    <th class="product-remove">Remove</th>
                    <th class="product-thumbnail"></th>
                    <th class="product-name"><span class="nobr"><?php 
    _e('Product Name', 'jigoshop');
    ?>
</span></th>
                    <th class="product-price"><span class="nobr"><?php 
    _e('Unit Price', 'jigoshop');
    ?>
</span></th>
                    <th class="product-quantity"><?php 
    _e('Quantity', 'jigoshop');
    ?>
</th>
                    <th class="product-subtotal"><?php 
    _e('Price', 'jigoshop');
    ?>
</th>
                </tr>
                <?php 
    do_action('jigoshop_shop_table_cart_head');
    ?>
            </thead>
            <tbody>
                <?php 
    if (sizeof(jigoshop_cart::$cart_contents) > 0) {
        foreach (jigoshop_cart::$cart_contents as $cart_item_key => $values) {
            $_product = $values['data'];
            if ($_product->exists() && $values['quantity'] > 0) {
                $additional_description = jigoshop_cart::get_item_data($values);
                ?>
                            <tr>
                                <td class="product-remove"><a href="<?php 
                echo esc_url(jigoshop_cart::get_remove_url($cart_item_key));
                ?>
" class="remove" title="<?php 
                echo esc_attr(__('Remove this item.', 'jigoshop'));
                ?>
">&times;</a></td>
                                <td class="product-thumbnail"><a href="<?php 
                echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key));
                ?>
">
                                    <?php 
                if ($values['variation_id'] && has_post_thumbnail($values['variation_id'])) {
                    echo get_the_post_thumbnail($values['variation_id'], 'shop_tiny');
                } else {
                    if (has_post_thumbnail($values['product_id'])) {
                        echo get_the_post_thumbnail($values['product_id'], 'shop_tiny');
                    } else {
                        echo '<img src="' . jigoshop::assets_url() . '/assets/images/placeholder.png" alt="Placeholder" width="' . jigoshop::get_var('shop_tiny_w') . '" height="' . jigoshop::get_var('shop_tiny_h') . '" />';
                    }
                }
                ?>
</a>
                                </td>

                                <td class="product-name">
                                    <a href="<?php 
                echo esc_url(apply_filters('jigoshop_product_url_display_in_cart', get_permalink($values['product_id']), $cart_item_key));
                ?>
"><?php 
                echo apply_filters('jigoshop_cart_product_title', $_product->get_title(), $_product);
                ?>
</a>
                                    <?php 
                echo $additional_description;
                ?>
                                    <?php 
                if (!empty($values['variation_id'])) {
                    $product_id = $values['variation_id'];
                } else {
                    $product_id = $values['product_id'];
                }
                $custom_products = (array) jigoshop_session::instance()->customized_products;
                $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : '';
                if (!empty($custom_products[$product_id])) {
                    ?>
											<dl class="customization">
												<dt class="customized_product_label"><?php 
                    echo apply_filters('jigoshop_customized_product_label', __('Personal: ', 'jigoshop'));
                    ?>
</dt>
												<dd class="customized_product"><?php 
                    echo esc_textarea($custom);
                    ?>
</dd>
											</dl>
											<?php 
                }
                ?>
                                </td>
                                <td class="product-price"><span class="m-label">Unit price:</span><?php 
                echo jigoshop_price($_product->get_price());
                ?>
</td>
                                <td class="product-quantity">
                                    <span class="m-label">Quantity:</span>
                                     <div class="quantity"><input name="cart[<?php 
                echo $cart_item_key;
                ?>
][qty]" value="<?php 
                echo esc_attr($values['quantity']);
                ?>
" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
                                </td>
                                <td class="product-subtotal"><span class="m-label">Price:</span><?php 
                echo jigoshop_price($_product->get_price() * $values['quantity']);
                ?>
</td>
                            </tr>
                            <?php 
            }
        }
    }
    do_action('jigoshop_shop_table_cart_body');
    ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="6" class="actions">

                        <?php 
    $coupons = JS_Coupons::get_coupons();
    if (!empty($coupons)) {
        ?>
                            <div class="coupon">
                                <label for="coupon_code"><?php 
        _e('Coupon', 'jigoshop');
        ?>
:</label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" />
                                <input type="submit" class="button" name="apply_coupon" value="<?php 
        _e('Apply Coupon', 'jigoshop');
        ?>
" />
                            </div>
                        <?php 
    }
    ?>

                        <?php 
    jigoshop::nonce_field('cart');
    ?>
                        <input type="submit" class="button" name="update_cart" value="<?php 
    _e('Update Shopping Cart', 'jigoshop');
    ?>
" /> <a href="<?php 
    echo esc_url(jigoshop_cart::get_checkout_url());
    ?>
" class="checkout-button button-alt"><?php 
    _e('Proceed to Checkout &rarr;', 'jigoshop');
    ?>
</a>
                    </td>
                </tr>
                <?php 
    if (count(jigoshop_cart::$applied_coupons)) {
        ?>
                    <tr>
                        <td colspan="6" class="applied-coupons">
                            <div>
                                <span class="applied-coupons-label"><?php 
        _e('Applied Coupons: ', 'jigoshop');
        ?>
</span>
								<?php 
        foreach (jigoshop_cart::$applied_coupons as $code) {
            ?>
                                <a href="?unset_coupon=<?php 
            echo $code;
            ?>
" id="<?php 
            echo $code;
            ?>
" class="applied-coupons-values"><?php 
            echo $code;
            ?>
									<span class="close">&times;</span>
								</a>
								<?php 
        }
        ?>
                            </div>
                        </td>
                    </tr>
                    <?php 
    }
    do_action('jigoshop_shop_table_cart_foot');
    ?>
            </tfoot>
            <?php 
    do_action('jigoshop_shop_table_cart');
    ?>
        </table>
    </form>
    <div class="cart-collaterals">

        <?php 
    do_action('cart-collaterals');
    ?>

        <div class="cart_totals">
            <?php 
    // Hide totals if customer has set location and there are no methods going there
    $available_methods = jigoshop_shipping::get_available_shipping_methods();
    $jigoshop_options = Jigoshop_Base::get_options();
    if ($available_methods || !jigoshop_customer::get_shipping_country() || !jigoshop_shipping::is_enabled()) {
        ?>
                <h2><?php 
        _e('Cart Totals', 'jigoshop');
        ?>
</h2>

                <div class="cart_totals_table">
                    <table cellspacing="0" cellpadding="0">
                        <tbody>

                            <tr>
							   <?php 
        $price_label = jigoshop_cart::show_retail_price() ? __('Retail Price', 'jigoshop') : __('Subtotal', 'jigoshop');
        ?>

								<th class="cart-row-subtotal-title"><?php 
        echo $price_label;
        ?>
</th>
                                <td class="cart-row-subtotal"><?php 
        echo jigoshop_cart::get_cart_subtotal();
        ?>
</td>
                            </tr>

                            <?php 
        if (jigoshop_cart::get_cart_shipping_total()) {
            ?>
							<tr>
                                <th class="cart-row-shipping-title"><?php 
            _e('Shipping', 'jigoshop');
            ?>
 <small><?php 
            echo jigoshop_countries::shipping_to_prefix() . ' ' . __(jigoshop_countries::$countries[jigoshop_customer::get_shipping_country()], 'jigoshop');
            ?>
</small></th>
                                <td class="cart-row-shipping"><?php 
            echo jigoshop_cart::get_cart_shipping_total();
            ?>
 <small><?php 
            echo jigoshop_cart::get_cart_shipping_title();
            ?>
</small></td>
                            </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (jigoshop_cart::show_retail_price()) {
            ?>
                                <tr>
                                    <th class="cart-row-subtotal-title"><?php 
            _e('Subtotal', 'jigoshop');
            ?>
</th>
                                    <td class="cart-row-subtotal"><?php 
            echo jigoshop_cart::get_cart_subtotal(true, true);
            ?>
</td>
                                </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (jigoshop_cart::tax_after_coupon()) {
            ?>
                                <tr class="discount">
                                    <th class="cart-row-discount-title"><?php 
            _e('Discount', 'jigoshop');
            ?>
</th>
									<td class="cart-row-discount">-<?php 
            echo jigoshop_cart::get_total_discount();
            ?>
</td>
                                </tr>
                            <?php 
        }
        ?>

                            <?php 
        if (Jigoshop_Base::get_options()->get_option('jigoshop_calc_taxes') == 'yes') {
            foreach (jigoshop_cart::get_applied_tax_classes() as $tax_class) {
                if (jigoshop_cart::get_tax_for_display($tax_class)) {
                    ?>
                                        <tr>
                                            <th class="cart-row-tax-title"><?php 
                    echo jigoshop_cart::get_tax_for_display($tax_class);
                    ?>
</th>
                                            <td class="cart-row-tax"><?php 
                    echo jigoshop_cart::get_tax_amount($tax_class);
                    ?>
</td>
                                        </tr>
                                    <?php 
                }
            }
        }
        ?>

							<?php 
        if (!jigoshop_cart::tax_after_coupon() && jigoshop_cart::get_total_discount()) {
            ?>
							<tr class="discount">
								<th class="cart-row-discount-title"><?php 
            _e('Discount', 'jigoshop');
            ?>
</th>
								<td class="cart-row-discount">-<?php 
            echo jigoshop_cart::get_total_discount();
            ?>
</td>
							</tr>
							<?php 
        }
        ?>

							<tr>
								<th class="cart-row-total-title"><strong><?php 
        _e('Total', 'jigoshop');
        ?>
</strong></th>
								<td class="cart-row-total"><strong><?php 
        echo jigoshop_cart::get_total();
        ?>
</strong></td>
							</tr>

						</tbody>
					</table>
				</div>
			<?php 
    } else {
        echo '<p>' . __(jigoshop_shipping::get_shipping_error_message(), 'jigoshop') . '</p>';
    }
    ?>
		</div>

		<?php 
    jigoshop_shipping_calculator();
    ?>

	</div>
	<?php 
}
示例#15
0
 /**
  * Get the shop's taxation rate using find_rate()
  *
  * @param string $tax_class is the tax class (not object)
  * @param bool $rate_only
  * @return int
  */
 public function get_shop_base_rate($tax_class = '*', $rate_only = true)
 {
     $country = jigoshop_countries::get_base_country();
     $state = jigoshop_countries::get_base_state();
     $state = $state && jigoshop_countries::country_has_states($country) ? $state : '*';
     $rate = $this->find_rate($country, $state, $tax_class);
     return $rate_only ? $rate['rate'] : $rate;
 }
示例#16
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
	}
示例#17
0
 public static function get_tax_for_display($tax_class)
 {
     $return = false;
     if (jigoshop_cart::get_tax_amount($tax_class, false) > 0 && jigoshop_cart::get_tax_rate($tax_class) > 0 || jigoshop_cart::get_tax_rate($tax_class) !== false) {
         $return = self::$tax->get_tax_class_for_display($tax_class) . ' (' . (double) jigoshop_cart::get_tax_rate($tax_class) . '%) ';
         // only show estimated tag when customer is on the cart page and no shipping calculator is enabled to be able to change country
         if (!jigoshop_shipping::show_shipping_calculator() && is_cart()) {
             $return .= '<small>' . sprintf(__('estimated for: %s', 'jigoshop'), jigoshop_countries::get_country(jigoshop_tax::get_customer_country())) . '</small>';
         }
     }
     return $return;
 }
    /**
     * 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;
        }
    }
示例#19
0
<?php

/**
 * @var $name string Name of the widget
 * @var $country string Currently selected country
 * @var $state string Currently selected state
 */
?>
<select id="jigoshop_<?php 
echo $name;
?>
" class="single_select_country" name="jigoshop[<?php 
echo $name;
?>
]">
<?php 
echo jigoshop_countries::country_dropdown_options($country, $state, true, false, false, false);
?>
</select>
<script type="text/javascript">
	/*<![CDATA[*/
	jQuery(function($){
		$("#jigoshop_<?php 
echo $name;
?>
").select2({ width: '25em' });
	});
	/*]]>*/
</script>
示例#20
0
    function jigoshop_shipping_calculator()
    {
        if (jigoshop_cart::needs_shipping()) {
            ?>
		<form class="shipping_calculator" action="<?php 
            echo jigoshop_cart::get_cart_url();
            ?>
" method="post">
			<h4><a href="#" class="shipping-calculator-button"><?php 
            _e('Calculate Shipping', 'jigoshop');
            ?>
 <span>&darr;</span></a></h4>
			<section class="shipping-calculator-form">
			<p class="form-row">
				<select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state">
					<option value=""><?php 
            _e('Select a country&hellip;', 'jigoshop');
            ?>
</option>
					<?php 
            foreach (jigoshop_countries::get_allowed_countries() as $key => $value) {
                echo '<option value="' . $key . '"';
                if (jigoshop_customer::get_shipping_country() == $key) {
                    echo 'selected="selected"';
                }
                echo '>' . $value . '</option>';
            }
            ?>
				</select>
			</p>
			<div class="col2-set">
				<p class="form-row col-1">
					<?php 
            $current_cc = jigoshop_customer::get_shipping_country();
            $current_r = jigoshop_customer::get_shipping_state();
            $states = jigoshop_countries::$states;
            if (isset($states[$current_cc][$current_r])) {
                // Dropdown
                ?>
							<span>
								<select name="calc_shipping_state" id="calc_shipping_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>';
                }
                ?>
</select>
							</span>
							<?php 
            } else {
                // Input
                ?>
							<input type="text" class="input-text" value="<?php 
                echo $current_r;
                ?>
" placeholder="<?php 
                _e('state', 'jigoshop');
                ?>
" name="calc_shipping_state" id="calc_shipping_state" />
							<?php 
            }
            ?>
				</p>
				<p class="form-row col-2">
					<input type="text" class="input-text" value="<?php 
            echo jigoshop_customer::get_shipping_postcode();
            ?>
" placeholder="<?php 
            _e('Postcode/Zip', 'jigoshop');
            ?>
" title="<?php 
            _e('Postcode', 'jigoshop');
            ?>
" name="calc_shipping_postcode" id="calc_shipping_postcode" />
				</p>
			</div>
			<p><button type="submit" name="calc_shipping" value="1" class="button"><?php 
            _e('Update Totals', 'jigoshop');
            ?>
</button></p>
			<?php 
            jigoshop::nonce_field('cart');
            ?>
			</section>
		</form>
		<?php 
        }
    }
function jigoshop_admin_option_display($options)
{
    if (empty($options)) {
        return false;
    }
    $counter = 1;
    foreach ($options as $value) {
        switch ($value['type']) {
            case 'string':
                ?>
<tr>
				<th scope="row"><?php 
                echo $value['name'];
                ?>
</th>
				<td><?php 
                echo $value['desc'];
                ?>
</td>
			  </tr><?php 
                break;
            case 'tab':
                ?>
<div id="<?php 
                echo $value['type'] . $counter;
                ?>
" class="panel">
			  <table class="form-table"><?php 
                break;
            case 'title':
                ?>
<thead>
				<tr>
					<th scope="col" colspan="2">
						<h3 class="title"><?php 
                echo $value['name'];
                ?>
</h3>
						<?php 
                if (!empty($value['desc'])) {
                    ?>
						<p><?php 
                    echo $value['desc'];
                    ?>
</p>
						<?php 
                }
                ?>
					</th>
				</tr>
			  </thead><?php 
                break;
            case 'button':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99" ></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<a  id="<?php 
                echo esc_attr($value['id']);
                ?>
"
						class="button <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
						style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
						href="<?php 
                if (!empty($value['href'])) {
                    echo esc_attr($value['href']);
                }
                ?>
"
					><?php 
                if (!empty($value['desc'])) {
                    echo $value['desc'];
                }
                ?>
</a>
				</td>
			  </tr><?php 
                break;
            case 'checkbox':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99" ></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<input
					id="<?php 
                echo esc_attr($value['id']);
                ?>
"
					type="checkbox"
					class="jigoshop-input jigoshop-checkbox <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
					style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
					name="<?php 
                echo esc_attr($value['id']);
                ?>
"
					<?php 
                if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
                    echo checked(get_option($value['id']), 'yes', false);
                } else {
                    if (isset($value['std'])) {
                        echo checked($value['std'], 'yes', false);
                    }
                }
                ?>
 />
					<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                if (!empty($value['desc'])) {
                    echo $value['desc'];
                }
                ?>
</label>
				</td>
			  </tr><?php 
                break;
            case 'text':
            case 'number':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>

				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
"
						id="<?php 
                echo esc_attr($value['id']);
                ?>
"
						type="<?php 
                echo $value['type'];
                ?>
"
						<?php 
                if ($value['type'] == 'number' && !empty($value['restrict']) && is_array($value['restrict'])) {
                    ?>
						min="<?php 
                    echo isset($value['restrict']['min']) ? $value['restrict']['min'] : '';
                    ?>
"
						max="<?php 
                    echo isset($value['restrict']['max']) ? $value['restrict']['max'] : '';
                    ?>
"
						step="<?php 
                    echo isset($value['restrict']['step']) ? $value['restrict']['step'] : 'any';
                    ?>
"
						<?php 
                }
                ?>
						class="regular-text <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
						style="<?php 
                if (!empty($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
						placeholder="<?php 
                if (!empty($value['placeholder'])) {
                    echo esc_attr($value['placeholder']);
                }
                ?>
"
						value="<?php 
                if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
                    echo esc_attr(get_option($value['id']));
                } else {
                    if (isset($value['std'])) {
                        echo esc_attr($value['std']);
                    }
                }
                ?>
" />
					<?php 
                if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) {
                    ?>
							<br /><small><?php 
                    echo $value['desc'];
                    ?>
</small>
					<?php 
                } elseif (!empty($value['desc'])) {
                    ?>
						<?php 
                    echo $value['desc'];
                    ?>
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'select':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                if (!empty($value['name'])) {
                    ?>
					<label for="<?php 
                    echo esc_attr($value['id']);
                    ?>
"><?php 
                    echo $value['name'];
                    ?>
</label>
					<?php 
                }
                ?>
				</th>
				<td>
					<select name="<?php 
                echo esc_attr($value['id']);
                ?>
"
							id="<?php 
                echo esc_attr($value['id']);
                ?>
"
							style="<?php 
                if (isset($value['css'])) {
                    echo esc_attr($value['css']);
                }
                ?>
"
							class="<?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
							<?php 
                if (!empty($value['multiple'])) {
                    echo 'multiple="multiple"';
                }
                ?>
							<?php 
                if (!empty($value['class']) && $value['class'] == 'chzn-select' && !empty($value['placeholder'])) {
                    ?>
							data-placeholder="<?php 
                    _e(esc_attr($value['placeholder']));
                    ?>
"
							<?php 
                }
                ?>
					>

					<?php 
                $selected = get_option($value['id']);
                $selected = !empty($selected) ? $selected : $value['std'];
                ?>
					<?php 
                foreach ($value['options'] as $key => $val) {
                    ?>
						<option value="<?php 
                    echo esc_attr($key);
                    ?>
"
						<?php 
                    if (!is_array($selected) && $selected == $key || is_array($selected) && in_array($key, $selected)) {
                        ?>
								selected="selected"
						<?php 
                    }
                    ?>
						>
							<?php 
                    echo ucfirst($val);
                    ?>
						</option>
					<?php 
                }
                ?>
					</select>
					<?php 
                if (!empty($value['desc']) && (!empty($value['name']) && empty($value['group']))) {
                    ?>
						<br /><small><?php 
                    echo $value['desc'];
                    ?>
</small>
					<?php 
                } elseif (!empty($value['desc'])) {
                    ?>
						<?php 
                    echo $value['desc'];
                    ?>
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'radio':
                ?>
<tr>
				<th scope="row"<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                if (!empty($value['tip'])) {
                    ?>
					<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a>
					<?php 
                }
                ?>
					<?php 
                echo $value['name'];
                ?>
				</th>
				<td<?php 
                if (empty($value['name'])) {
                    ?>
 style="padding-top:0px;"<?php 
                }
                ?>
>
					<?php 
                foreach ($value['options'] as $key => $val) {
                    ?>
					<label class="radio">
					<input type="radio"
						   name="<?php 
                    echo esc_attr($value['id']);
                    ?>
"
						   id="<?php 
                    echo esc_attr($key);
                    ?>
"
						   value="<?php 
                    echo esc_attr($key);
                    ?>
"
						   class="<?php 
                    if (!empty($value['class'])) {
                        echo esc_attr($value['class']);
                    }
                    ?>
"
						   <?php 
                    if (get_option($value['id']) == $key) {
                        ?>
 checked="checked" <?php 
                    }
                    ?>
>
					<?php 
                    echo esc_attr(ucfirst($val));
                    ?>
					</label><br />
					<?php 
                }
                ?>
				</td>
			  </tr><?php 
                break;
            case 'image_size':
                $sizes = array('jigoshop_shop_tiny' => 'jigoshop_use_wordpress_tiny_crop', 'jigoshop_shop_thumbnail' => 'jigoshop_use_wordpress_thumbnail_crop', 'jigoshop_shop_small' => 'jigoshop_use_wordpress_catalog_crop', 'jigoshop_shop_large' => 'jigoshop_use_wordpress_featured_crop');
                $altSize = $sizes[$value['id']];
                ?>
<tr>
				<th scope="row"><?php 
                echo $value['name'];
                ?>
</label></th>
				<td valign="top" style="line-height:25px;height:25px;">

					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
_w"
						   id="<?php 
                echo esc_attr($value['id']);
                ?>
_w"
						   type="number"
						   min="0"
						   style="width:60px;"
						   placeholder=<?php 
                if (!empty($value['placeholder'])) {
                    echo $value['placeholder'];
                }
                ?>
						   value="<?php 
                if ($size = get_option($value['id'] . '_w')) {
                    echo $size;
                } else {
                    echo $value['std'];
                }
                ?>
"
					/>

					<label for="<?php 
                echo esc_attr($value['id']);
                ?>
_h">x</label>

					<input name="<?php 
                echo esc_attr($value['id']);
                ?>
_h"
						   id="<?php 
                echo esc_attr($value['id']);
                ?>
_h"
						   type="number"
						   min="0"
						   style="width:60px;"
						   placeholder=<?php 
                if (!empty($value['placeholder'])) {
                    echo $value['placeholder'];
                }
                ?>
						   value="<?php 
                if ($size = get_option($value['id'] . '_h')) {
                    echo $size;
                } else {
                    echo $value['std'];
                }
                ?>
"
					/>

					<input
					id="<?php 
                echo esc_attr($altSize);
                ?>
"
					type="checkbox"
					class="jigoshop-input jigoshop-checkbox"
					name="<?php 
                echo esc_attr($altSize);
                ?>
"
					<?php 
                if (get_option($altSize) !== false && get_option($altSize) !== null) {
                    echo checked(get_option($altSize), 'yes', false);
                }
                ?>
 />
					<label for="<?php 
                echo esc_attr($altSize);
                ?>
"> <?php 
                echo __('Crop', 'jigoshop');
                ?>
</label>
					<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
				</td>
			</tr><?php 
                break;
            case 'textarea':
                ?>
<tr>
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<textarea <?php 
                if (isset($value['args'])) {
                    echo $value['args'] . ' ';
                }
                ?>
								name="<?php 
                echo esc_attr($value['id']);
                ?>
"
								id="<?php 
                echo esc_attr($value['id']);
                ?>
"
								class="large-text <?php 
                if (!empty($value['class'])) {
                    echo esc_attr($value['class']);
                }
                ?>
"
								style="<?php 
                echo esc_attr($value['css']);
                ?>
"
								placeholder="<?php 
                if (!empty($value['placeholder'])) {
                    echo esc_attr($value['placeholder']);
                }
                ?>
"
						><?php 
                echo esc_textarea(get_option($value['id']) ? stripslashes(get_option($value['id'])) : $value['std']);
                ?>
</textarea>
						<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
					</td>
				</tr><?php 
                break;
            case 'tabend':
                ?>
</table></div><?php 
                $counter = $counter + 1;
                break;
            case 'single_select_page':
                $args = array('name' => $value['id'], 'id' => $value['id'] . '" style="width: 200px;', 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'selected' => (int) get_option($value['id']));
                if (!empty($value['args'])) {
                    $args = wp_parse_args($value['args'], $args);
                }
                ?>
<tr class="single_select_page">
				<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
				<td>
					<?php 
                wp_dropdown_pages($args);
                ?>
					<br /><small><?php 
                echo $value['desc'];
                ?>
</small>
				</td>
			</tr><?php 
                break;
            case 'single_select_country':
                $countries = jigoshop_countries::$countries;
                $country_setting = (string) get_option($value['id']);
                if (strstr($country_setting, ':')) {
                    $country = current(explode(':', $country_setting));
                    $state = end(explode(':', $country_setting));
                } else {
                    $country = $country_setting;
                    $state = '*';
                }
                ?>
<tr class="multi_select_countries">
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label for="<?php 
                echo esc_attr($value['id']);
                ?>
"><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<select id="<?php 
                echo esc_attr($value['id']);
                ?>
" name="<?php 
                echo esc_attr($value['id']);
                ?>
" title="Country" style="width: 150px;">
						<?php 
                $show_all = $value['id'] != 'jigoshop_default_country';
                echo jigoshop_countries::country_dropdown_options($country, $state, false, $show_all);
                ?>
						</select>
					</td>
				</tr><?php 
                if (!$show_all && jigoshop_countries::country_has_states($country) && $state == '*') {
                    jigoshop_countries::base_country_notice();
                }
                break;
            case 'multi_select_countries':
                $countries = jigoshop_countries::$countries;
                asort($countries);
                $selections = (array) get_option($value['id']);
                ?>
<tr class="multi_select_countries">
					<th scope="row"><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label><?php 
                echo $value['name'];
                ?>
</label></th>
					<td>
						<div class="multi_select_countries">
							<ul><?php 
                if ($countries) {
                    foreach ($countries as $key => $val) {
                        ?>
<li><label>
								<input type="checkbox"
									   name="<?php 
                        echo esc_attr($value['id']) . '[]';
                        ?>
"
									   value="<?php 
                        echo esc_attr($key);
                        ?>
"
									   <?php 
                        if (in_array($key, $selections)) {
                            ?>
									   checked="checked"
									   <?php 
                        }
                        ?>
								/>
								<?php 
                        echo $val;
                        ?>
								</label></li><?php 
                    }
                }
                ?>
</ul>
						</div>
					</td>
				</tr><?php 
                break;
            case 'coupons':
                _deprecated_argument('jigoshop_admin_option_display', '1.3', 'The coupons type has no alternative. Use the new custom post Coupons Menu item under Jigoshop.');
                $coupons = new jigoshop_coupons();
                $coupon_codes = $coupons->get_coupons();
                ?>
		<style>
table{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
.table{width:100%;margin-bottom:18px;}
.table th,.table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:1px solid #dddddd;}
.table thead th{vertical-align:bottom;}
.table caption+thead tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child th,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child th,.table thead:first-child tr:first-child td{border-top:0;}
.table tbody+tbody{border-top:2px solid #dddddd;}
.table-condensed th,.table-condensed td{padding:4px 5px;}
.coupon-table th,.coupon-table td{padding:8px;line-height:18px;text-align:left;vertical-align:top;border-top:0px;}
</style>
			<tr><td><a href="#" class="add button" id="add_coupon"><?php 
                _e('+ Add Coupon', 'jigoshop');
                ?>
</a></td></tr>

			<table class="coupons table">
				<thead>
					<tr>
						<th>Coupon</th>
						<th>Type</th>
						<th>Amount</th>
						<th>Usage</th>
						<th>Controls</th>
					</tr>
				</thead>
				<tbody>

				<?php 
                /* Payment methods. */
                $payment_methods = array();
                $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
                if (!empty($available_gateways)) {
                    foreach ($available_gateways as $id => $info) {
                        $payment_methods[$id] = $info->title;
                    }
                }
                /* Coupon types. */
                $discount_types = jigoshop_coupons::get_coupon_types();
                /* Product categories. */
                $categories = get_terms('product_cat', array('hide_empty' => false));
                $coupon_cats = array();
                foreach ($categories as $category) {
                    $coupon_cats[$category->term_id] = $category->name;
                }
                $i = -1;
                if ($coupon_codes && is_array($coupon_codes) && sizeof($coupon_codes) > 0) {
                    foreach ($coupon_codes as $coupon) {
                        $i++;
                        ?>
				<tr>
				<td style="width:500px;">
				<table class="coupon-table form-table" id="coupons_table_<?php 
                        echo $i;
                        ?>
">
				<?php 
                        echo $coupon['code'];
                        ?>

				<tbody class="couponDisplay" id="coupons_rows_<?php 
                        echo $i;
                        ?>
">
				<?php 
                        $selected_type = '';
                        foreach ($discount_types as $type => $label) {
                            if ($coupon['type'] == $type) {
                                $selected_type = $type;
                            }
                        }
                        $options3 = array(array('name' => __('Code', 'jigoshop'), 'tip' => __('The coupon code a customer enters on the cart or checkout page.', 'jigoshop'), 'id' => 'coupon_code[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'class' => 'coupon_code', 'type' => 'text', 'std' => esc_attr($coupon['code'])), array('name' => __('Type', 'jigoshop'), 'tip' => __('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'jigoshop'), 'id' => 'coupon_type[' . esc_attr($i) . ']', 'css' => 'width:200px;', 'type' => 'select', 'std' => $selected_type, 'options' => $discount_types), array('name' => __('Amount', 'jigoshop'), 'tip' => __('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'jigoshop'), 'id' => 'coupon_amount[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => esc_attr($coupon['amount'])), array('name' => __('Usage limit', 'jigoshop'), 'desc' => __(sprintf('Times used: %s', !empty($coupon['usage']) ? $coupon['usage'] : '0'), 'jigoshop'), 'placeholder' => __('No limit', 'jigoshop'), 'tip' => __('Control how many times this coupon may be used.', 'jigoshop'), 'id' => 'usage_limit[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['usage_limit']) ? $coupon['usage_limit'] : ''), array('name' => __('Order subtotal', 'jigoshop'), 'placeholder' => __('No min', 'jigoshop'), 'desc' => __('Min', 'jigoshop'), 'tip' => __('Set the required subtotal for this coupon to be valid on an order.', 'jigoshop'), 'id' => 'order_total_min[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_min']) ? $coupon['order_total_min'] : '', 'group' => true), array('desc' => __('Max', 'jigoshop'), 'placeholder' => __('No max', 'jigoshop'), 'id' => 'order_total_max[' . esc_attr($i) . ']', 'css' => 'width:60px;', 'type' => 'number', 'restrict' => array('min' => 0), 'std' => !empty($coupon['order_total_max']) ? $coupon['order_total_max'] : '', 'group' => true), array('name' => __('Payment methods', 'jigoshop'), 'tip' => __('Which payment methods are allowed for this coupon to be effective?', 'jigoshop'), 'id' => 'coupon_pay_methods[' . esc_attr($i) . '][]', 'css' => 'width:200px;', 'class' => 'chzn-select', 'type' => 'select', 'placeholder' => 'Any method', 'multiple' => true, 'std' => !empty($coupon['coupon_pay_methods']) ? $coupon['coupon_pay_methods'] : '', 'options' => $payment_methods));
                        jigoshop_admin_option_display($options3);
                        ?>

					<tr>
						<th scope="row">
							<a href="#" tip="<?php 
                        _e('Control which products this coupon can apply to.', 'jigoshop');
                        ?>
" class="tips" tabindex="99"></a>
							<label for="product_ids_<?php 
                        echo esc_attr($i);
                        ?>
"><?php 
                        _e('Products', 'jigoshop');
                        ?>
</label>
						</th>

						<td>
							<select id="product_ids_<?php 
                        echo esc_attr($i);
                        ?>
" style="width:200px;" name="product_ids[<?php 
                        echo esc_attr($i);
                        ?>
][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php 
                        _e('Any product', 'jigoshop');
                        ?>
">
								<?php 
                        $product_ids = $coupon['products'];
                        if ($product_ids) {
                            foreach ($product_ids as $product_id) {
                                $title = get_the_title($product_id);
                                $sku = get_post_meta($product_id, '_sku', true);
                                if (!$title) {
                                    continue;
                                }
                                if (isset($sku) && $sku) {
                                    $sku = ' (SKU: ' . $sku . ')';
                                }
                                echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>';
                            }
                        }
                        ?>
							</select> <?php 
                        _e('Include', 'jigoshop');
                        ?>
						</td>
					  </tr>

					<tr>
						<th scope="row"></th>
						<td style="padding-top:0px;">
							<select id="exclude_product_ids_<?php 
                        echo esc_attr($i);
                        ?>
" style="width:200px;" name="exclude_product_ids[<?php 
                        echo esc_attr($i);
                        ?>
][]" style="width:100px" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php 
                        _e('Any product', 'jigoshop');
                        ?>
">
								<?php 
                        if (!empty($coupon['exclude_products'])) {
                            foreach ($coupon['exclude_products'] as $product_id) {
                                $title = get_the_title($product_id);
                                $sku = get_post_meta($product_id, '_sku', true);
                                if (!$title) {
                                    continue;
                                }
                                if (isset($sku) && $sku) {
                                    $sku = ' (SKU: ' . $sku . ')';
                                }
                                echo '<option value="' . $product_id . '" selected="selected">' . $title . $sku . '</option>';
                            }
                        }
                        ?>
							</select> <?php 
                        _e('Exclude', 'jigoshop');
                        ?>
						</td>
					  </tr>

					<?php 
                        $options2 = array(array('name' => __('Categories', 'jigoshop'), 'desc' => __('Include', 'jigoshop'), 'tip' => __('Control which categories this coupon can apply to.', 'jigoshop'), 'id' => 'coupon_category[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['coupon_category']) ? $coupon['coupon_category'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('desc' => __('Exclude', 'jigoshop'), 'id' => 'exclude_categories[' . esc_attr($i) . '][]', 'type' => 'select', 'multiple' => true, 'std' => !empty($coupon['exclude_categories']) ? $coupon['exclude_categories'] : '', 'options' => $coupon_cats, 'class' => 'chzn-select', 'css' => 'width:200px;', 'placeholder' => 'Any category', 'group' => true), array('name' => __('Dates allowed', 'jigoshop'), 'desc' => __('From', 'jigoshop'), 'placeholder' => __('Any date', 'jigoshop'), 'tip' => __('Choose between which dates this coupon is enabled.', 'jigoshop'), 'id' => 'coupon_date_from[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_from']) ? date('Y-m-d', $coupon['date_from']) : '', 'group' => true), array('desc' => __('To', 'jigoshop'), 'placeholder' => __('Any date', 'jigoshop'), 'id' => 'coupon_date_to[' . esc_attr($i) . ']', 'css' => 'width:150px;', 'type' => 'text', 'class' => 'date-pick', 'std' => !empty($coupon['date_to']) ? date('Y-m-d', $coupon['date_to']) : '', 'group' => true), array('name' => __('Misc. settings', 'jigoshop'), 'desc' => 'Prevent other coupons', 'tip' => __('Prevent other coupons from being used while this one is applied to a cart.', 'jigoshop'), 'id' => 'individual[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['individual_use']) && $coupon['individual_use'] == 'yes' ? 'yes' : 'no'), array('desc' => 'Free shipping', 'tip' => __('Show the Free Shipping method on checkout with this enabled.', 'jigoshop'), 'id' => 'coupon_free_shipping[' . esc_attr($i) . ']', 'type' => 'checkbox', 'std' => isset($coupon['coupon_free_shipping']) && $coupon['coupon_free_shipping'] == 'yes' ? 'yes' : 'no'));
                        jigoshop_admin_option_display($options2);
                        ?>
					</tbody>
					</table>
					<script type="text/javascript">
						/* <![CDATA[ */
						jQuery(function() {
							jQuery("select#product_ids_<?php 
                        echo esc_attr($i);
                        ?>
").ajaxChosen({
								method: 	'GET',
								url: 		'<?php 
                        echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                        ?>
',
								dataType: 	'json',
								afterTypeDelay: 100,
								data:		{
									action: 		'jigoshop_json_search_products_and_variations',
									security: 		'<?php 
                        echo wp_create_nonce("search-products");
                        ?>
'
								}
							}, function (data) {

								var terms = {};

								jQuery.each(data, function (i, val) {
									terms[i] = val;
								});

								return terms;
							});
							jQuery("select#exclude_product_ids_<?php 
                        echo esc_attr($i);
                        ?>
").ajaxChosen({
								method: 	'GET',
								url: 		'<?php 
                        echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                        ?>
',
								dataType: 	'json',
								afterTypeDelay: 100,
								data:		{
									action: 		'jigoshop_json_search_products_and_variations',
									security: 		'<?php 
                        echo wp_create_nonce("search-products");
                        ?>
'
								}
							}, function (data) {

								var terms = {};

								jQuery.each(data, function (i, val) {
									terms[i] = val;
								});

								return terms;
							});
							jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
						});
						/* ]]> */
					</script>
				</td>
				<td><?php 
                        echo $discount_types[$selected_type];
                        ?>
</td>
				<td><?php 
                        echo !empty($coupon['amount']) ? $coupon['amount'] : '';
                        ?>
</td>
				<td><?php 
                        echo !empty($coupon['usage']) ? $coupon['usage'] : '0';
                        ?>
</td>
				<td>
					<a class="toggleCoupon" href="#coupons_rows_<?php 
                        echo $i;
                        ?>
"><?php 
                        _e('Show', 'jigoshop');
                        ?>
</a> /
					<a href="#" id="remove_coupon_<?php 
                        echo esc_attr($i);
                        ?>
" class="remove_coupon" title="<?php 
                        _e('Delete this Coupon', 'jigoshop');
                        ?>
"><?php 
                        _e('Delete', 'jigoshop');
                        ?>
</a>
				</td>
				</tr>
					<?php 
                    }
                }
                ?>
			<script type="text/javascript">

			jQuery('.couponDisplay').hide();

			/* <![CDATA[ */
			jQuery(function() {
				function toggle_coupons() {
					jQuery('a.toggleCoupon').click(function(e) {
						e.preventDefault();
						jQuery(this).text(jQuery(this).text() == '<?php 
                _e('Show', 'jigoshop');
                ?>
' ? '<?php 
                _e('Hide', 'jigoshop');
                ?>
' : '<?php 
                _e('Show', 'jigoshop');
                ?>
');

						var id = jQuery(this).attr('href').substr(1);
						jQuery('#' + id).toggle('slow');
					});
				}

				toggle_coupons();

				jQuery('#add_coupon').live('click', function(e){
					e.preventDefault();
					var size = jQuery('.couponDisplay').size();
					var new_coupon = '\
					<table class="coupon-table form-table" id="coupons_table_' + size + '">\
					<tbody class="couponDisplay" id="coupons_rows_[' + size + ']">\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('The coupon code a customer enters on the cart or checkout page.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_code[' + size + ']"><?php 
                _e('Code', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_code[' + size + ']" id="coupon_code[' + size + ']" type="text" class="regular-text coupon_code"\
								style="width:150px;" placeholder="" value="" />\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Cart - Applies to whole cart<br/>Product - Applies to individual products only. You must specify individual products.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_type[' + size + ']"><?php 
                _e('Type', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_type[' + size + ']" id="coupon_type[' + size + ']" style="width:150px;">\
									<option value="fixed_cart"><?php 
                _e('Cart Discount', 'jigoshop');
                ?>
</option>\
									<option value="percent"><?php 
                _e('Cart % Discount', 'jigoshop');
                ?>
</option>\
									<option value="fixed_product"><?php 
                _e('Product Discount', 'jigoshop');
                ?>
</option>\
									<option value="percent_product"><?php 
                _e('Product % Discount', 'jigoshop');
                ?>
</option>\
									</select>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Amount this coupon is worth. If it is a percentange, just include the number without the percentage sign.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_amount[' + size + ']"><?php 
                _e('Amount', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_amount[' + size + ']" id="coupon_amount[' + size + ']" type="number" min="0"\
								max="" class="regular-text " style="width:60px;" value=""\
								/>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control how many times this coupon may be used.', 'jigoshop');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="usage_limit[' + size + ']"><?php 
                _e('Usage limit', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input name="usage_limit[' + size + ']" id="usage_limit[' + size + ']" type="number" min="0"\
								max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No limit', 'jigoshop');
                ?>
"\
								value="" />\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Set the required subtotal for this coupon to be valid on an order.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="order_total_min[' + size + ']"><?php 
                _e('Order subtotal', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input name="order_total_min[' + size + ']" id="order_total_min[' + size + ']" type="number"\
								min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No min', 'jigoshop');
                ?>
"\
								value="" /><?php 
                _e('Min', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;"></th>\
							<td style="padding-top:0px;">\
								<input name="order_total_max[' + size + ']" id="order_total_max[' + size + ']" type="number"\
								min="0" max="" class="regular-text " style="width:60px;" placeholder="<?php 
                _e('No max', 'jigoshop');
                ?>
"\
								value="" /><?php 
                _e('Max', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Which payment methods are allowed for this coupon to be effective?', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="coupon_pay_methods[' + size + '][]"><?php 
                _e('Payment methods', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_pay_methods[' + size + '][]" id="coupon_pay_methods[' + size + '][]" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
									<?php 
                foreach ($payment_methods as $id => $label) {
                    echo '<option value="' . $id . '">' . $label . '</option>';
                }
                ?>
\
								</select>\
								<br />\
								<small></small>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control which products this coupon can apply to.', 'jigoshop');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="product_ids_' + size + '"><?php 
                _e('Products', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<select id="product_ids_' + size + '" style="width:200px;" name="product_ids[' + size + '][]"\
								style="width:100px" class="ajax_chosen_select_products_and_variations"\
								multiple="multiple" data-placeholder="<?php 
                _e('Any product', 'jigoshop');
                ?>
"></select><?php 
                _e('Include', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row"></th>\
							<td style="padding-top:0px;">\
								<select id="exclude_product_ids_' + size + '" style="width:200px;" name="exclude_product_ids[' + size + '][]"\
								style="width:100px" class="ajax_chosen_select_products_and_variations"\
								multiple="multiple" data-placeholder="<?php 
                _e('Any product', 'jigoshop');
                ?>
"></select><?php 
                _e('Exclude', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Control which categories this coupon can apply to.', 'jigoshop');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="coupon_category[' + size + '][]"><?php 
                _e('Categories', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<select name="coupon_category[' + size + '][]" id="coupon_category_' + size + '" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
								   <?php 
                $categories = get_terms('product_cat', array('hide_empty' => false));
                foreach ($categories as $category) {
                    echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
                }
                ?>
\
								</select><?php 
                _e('Include', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<label for="exclude_categories[' + size + '][]"></label>\
							</th>\
							<td>\
								<select name="exclude_categories[' + size + '][]" id="exclude_categories_' + size + '" style="width:200px;"\
								class="chzn-select" multiple="multiple">\
									<?php 
                $categories = get_terms('product_cat', array('hide_empty' => false));
                foreach ($categories as $category) {
                    echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
                }
                ?>
\
								</select><?php 
                _e('Exclude', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Choose between which dates this coupon is enabled.', 'jigoshop');
                ?>
" class="tips"\
								tabindex="99"></a>\
								<label for="coupon_date_from[' + size + ']"><?php 
                _e('Dates allowed', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input name="coupon_date_from[' + size + ']" id="coupon_date_from[' + size + ']" type="text"\
								class="regular-text date-pick" style="width:150px;" placeholder="<?php 
                _e('Any date', 'jigoshop');
                ?>
"\
								value="" /><?php 
                _e('From', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;"></th>\
							<td style="padding-top:0px;">\
								<input name="coupon_date_to[' + size + ']" id="coupon_date_to[' + size + ']" type="text" class="regular-text date-pick"\
								style="width:150px;" placeholder="<?php 
                _e('Any date', 'jigoshop');
                ?>
" value="" /><?php 
                _e('To', 'jigoshop');
                ?>
</td>\
						</tr>\
						<tr>\
							<th scope="row">\
								<a href="#" tip="<?php 
                _e('Prevent other coupons from being used while this one is applied to a cart.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
								<label for="individual[' + size + ']"><?php 
                _e('Misc. settings', 'jigoshop');
                ?>
</label>\
							</th>\
							<td>\
								<input id="individual[' + size + ']" type="checkbox" class="jigoshop-input jigoshop-checkbox "\
								style="" name="individual[' + size + ']" />\
								<label for="individual[' + size + ']"><?php 
                _e('Prevent other coupons', 'jigoshop');
                ?>
</label>\
							</td>\
						</tr>\
						<tr>\
							<th scope="row" style="padding-top:0px;">\
								<a href="#" tip="<?php 
                _e('Show the Free Shipping method on checkout with this enabled.', 'jigoshop');
                ?>
"\
								class="tips" tabindex="99"></a>\
							</th>\
							<td style="padding-top:0px;">\
								<input id="coupon_free_shipping[' + size + ']" type="checkbox" class="jigoshop-input jigoshop-checkbox "\
								style="" name="coupon_free_shipping[' + size + ']" />\
								<label for="coupon_free_shipping[' + size + ']"><?php 
                _e('Free shipping', 'jigoshop');
                ?>
</label>\
							</td>\
						</tr>\
					</tbody>\
					</table>\
					';
					/* Add the table */
					jQuery('.coupons.table').before(new_coupon);
					jQuery('#coupons_table_' + size).hide().fadeIn('slow');

					jQuery("select#product_ids_" + size).ajaxChosen({
						method: 	'GET',
						url: 		'<?php 
                echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                ?>
',
						dataType: 	'json',
						afterTypeDelay: 100,
						data:		{
							action: 		'jigoshop_json_search_products_and_variations',
							security: 		'<?php 
                echo wp_create_nonce("search-products");
                ?>
'
						}
					}, function (data) {

						var terms = {};

						jQuery.each(data, function (i, val) {
							terms[i] = val;
						});

						return terms;
					});
					jQuery("select#exclude_product_ids_" + size).ajaxChosen({
						method: 	'GET',
						url: 		'<?php 
                echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php');
                ?>
',
						dataType: 	'json',
						afterTypeDelay: 100,
						data:		{
							action: 		'jigoshop_json_search_products_and_variations',
							security: 		'<?php 
                echo wp_create_nonce("search-products");
                ?>
'
						}
					}, function (data) {

						var terms = {};

						jQuery.each(data, function (i, val) {
							terms[i] = val;
						});

						return terms;
					});
					jQuery('a[href="#coupons_rows_'+size+'"]').click(function(e) {
						e.preventDefault();
						jQuery('#coupons_rows_'+size).toggle('slow', function() {
							// Stuff later?
						});
					});
					jQuery(".chzn-select").chosen();
					jQuery(".tips").tooltip();
					jQuery('.date-pick').datepicker( {dateFormat: 'yy-mm-dd', gotoCurrent: true} );
					return false;
				});
				jQuery('a.remove_coupon').live('click', function(){
					var answer = confirm("<?php 
                _e('Delete this coupon?', 'jigoshop');
                ?>
")
					if (answer) {
						jQuery('input', jQuery(this).parent().parent().children()).val('');
						jQuery(this).parent().parent().fadeOut();
					}
					return false;
				});
			});
		/* ]]> */
		</script>
						<?php 
                break;
            case 'tax_rates':
                $_tax = new jigoshop_tax();
                $tax_classes = $_tax->get_tax_classes();
                $tax_rates = get_option('jigoshop_tax_rates');
                $applied_all_states = array();
                ?>
<tr>
					<th><?php 
                if ($value['tip']) {
                    ?>
<a href="#" tip="<?php 
                    echo $value['tip'];
                    ?>
" class="tips" tabindex="99"></a><?php 
                }
                ?>
<label><?php 
                echo $value['name'];
                ?>
</label></th>
					<td id="tax_rates">
						<div class="taxrows">
			<?php 
                $i = -1;
                if ($tax_rates && is_array($tax_rates) && sizeof($tax_rates) > 0) {
                    function array_find($needle, $haystack)
                    {
                        foreach ($haystack as $key => $val) {
                            if ($needle == array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class'])) {
                                return $key;
                            }
                        }
                        return false;
                    }
                    function array_compare($tax_rates)
                    {
                        $after = array();
                        foreach ($tax_rates as $key => $val) {
                            $first_two = array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class']);
                            $found = array_find($first_two, $after);
                            if ($found !== false) {
                                $combined = $after[$found]["state"];
                                $combined2 = $after[$found]["country"];
                                $combined = !is_array($combined) ? array($combined) : $combined;
                                $combined2 = !is_array($combined2) ? array($combined2) : $combined2;
                                $after[$found] = array_merge($first_two, array("state" => array_merge($combined, array($val['state'])), "country" => array_merge($combined2, array($val['country']))));
                            } else {
                                $after = array_merge($after, array(array_merge($first_two, array("state" => $val['state'], "country" => $val['country']))));
                            }
                        }
                        return $after;
                    }
                    $tax_rates = array_compare($tax_rates);
                    foreach ($tax_rates as $rate) {
                        if ($rate['is_all_states'] && in_array(get_all_states_key($rate), $applied_all_states)) {
                            continue;
                        }
                        $i++;
                        // increment counter after check for all states having been applied
                        echo '<p class="taxrow">
					<select name="tax_classes[' . esc_attr($i) . ']" title="Tax Classes">
						<option value="*">' . __('Standard Rate', 'jigoshop') . '</option>';
                        if ($tax_classes) {
                            foreach ($tax_classes as $class) {
                                echo '<option value="' . sanitize_title($class) . '"';
                                if ($rate['class'] == sanitize_title($class)) {
                                    echo 'selected="selected"';
                                }
                                echo '>' . $class . '</option>';
                            }
                        }
                        echo '</select>

					<input type="text"
						   class="text" value="' . esc_attr($rate['label']) . '"
						   name="tax_label[' . esc_attr($i) . ']"
						   title="' . __('Online Label', 'jigoshop') . '"
						   placeholder="' . __('Online Label', 'jigoshop') . '"
						   maxlength="15" />';
                        echo '<select name="tax_country[' . esc_attr($i) . '][]" title="Country" multiple="multiple" style="width:250px;">';
                        if ($rate['is_all_states']) {
                            if (is_array($applied_all_states) && !in_array(get_all_states_key($rate), $applied_all_states)) {
                                $applied_all_states[] = get_all_states_key($rate);
                                jigoshop_countries::country_dropdown_options($rate['country'], '*');
                                //all-states
                            } else {
                                continue;
                            }
                        } else {
                            jigoshop_countries::country_dropdown_options($rate['country'], $rate['state']);
                        }
                        echo '</select>

					<input type="text"
						   class="text"
						   value="' . esc_attr($rate['rate']) . '"
						   name="tax_rate[' . esc_attr($i) . ']"
						   title="' . __('Rate', 'jigoshop') . '"
						   placeholder="' . __('Rate', 'jigoshop') . '"
						   maxlength="8" />%

					<label><input type="checkbox" name="tax_shipping[' . esc_attr($i) . ']" ';
                        if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                            echo 'checked="checked"';
                        }
                        echo ' /> ' . __('Apply to shipping', 'jigoshop') . '</label>

					<label><input type="checkbox" name="tax_compound[' . esc_attr($i) . ']" ';
                        if (isset($rate['compound']) && $rate['compound'] == 'yes') {
                            echo 'checked="checked"';
                        }
                        echo ' /> ' . __('Compound', 'jigoshop') . '</label>

					<a href="#" class="remove button">&times;</a></p>';
                    }
                }
                ?>
						</div>
						<p><a href="#" class="add button"><?php 
                _e('+ Add Tax Rule', 'jigoshop');
                ?>
</a></p>
					</td>
				</tr>
				<script type="text/javascript">
					/* <![CDATA[ */
					jQuery(function() {
						jQuery('#tax_rates a.add').live('click', function(){
							var size = jQuery('.taxrows .taxrow').size();

							// Add the row
							jQuery('<p class="taxrow"> \
								<select name="tax_classes[' + size + ']" title="Tax Classes"> \
									<option value="*"><?php 
                _e('Standard Rate', 'jigoshop');
                ?>
</option><?php 
                $tax_classes = $_tax->get_tax_classes();
                if ($tax_classes) {
                    foreach ($tax_classes as $class) {
                        echo '<option value="' . sanitize_title($class) . '">' . $class . '</option>';
                    }
                }
                ?>
</select><input type="text" class="text" name="tax_label[' + size + ']" title="<?php 
                _e('Online Label', 'jigoshop');
                ?>
" placeholder="<?php 
                _e('Online Label', 'jigoshop');
                ?>
" maxlength="15" />\
									</select><select name="tax_country[' + size + '][]" title="Country" multiple="multiple"><?php 
                jigoshop_countries::country_dropdown_options('', '', true);
                ?>
</select><input type="text" class="text" name="tax_rate[' + size + ']" title="<?php 
                _e('Rate', 'jigoshop');
                ?>
" placeholder="<?php 
                _e('Rate', 'jigoshop');
                ?>
" maxlength="8" />%\
									<label><input type="checkbox" name="tax_shipping[' + size + ']" /> <?php 
                _e('Apply to shipping', 'jigoshop');
                ?>
</label>\
									<label><input type="checkbox" name="tax_compound[' + size + ']" /> <?php 
                _e('Compound', 'jigoshop');
                ?>
</label><a href="#" class="remove button">&times;</a>\
							</p>').appendTo('#tax_rates div.taxrows');
												return false;
											});
											jQuery('#tax_rates a.remove').live('click', function(){
												var answer = confirm("<?php 
                _e('Delete this rule?', 'jigoshop');
                ?>
");
												if (answer) {
													jQuery('input', jQuery(this).parent()).val('');
													jQuery(this).parent().hide();
												}
												return false;
											});
										});
										/* ]]> */
				</script>
			<?php 
                break;
            case "shipping_options":
                foreach (jigoshop_shipping::get_all_methods() as $method) {
                    $method->admin_options();
                }
                break;
            case "gateway_options":
                foreach (jigoshop_payment_gateways::payment_gateways() as $gateway) {
                    $gateway->admin_options();
                }
                break;
        }
    }
}