/**
  * template method that determines the algorithm to send data to and from the shipping
  * server. This method should be called from the implementing classes calculate shipping
  * function.
  */
 protected final function calculate_rate()
 {
     $services_to_use = $this->filter_services();
     $this->has_error = false;
     // canada post will return all services you have chosen in your online account in the response.
     // most configurations happen on canada post site. Therefore any other services that do something
     // similar, we don't want to take the approach that there are services to loop through here.
     if ($services_to_use) {
         foreach ($services_to_use as $current_service) {
             if (!jigoshop_shipping::show_shipping_calculator() && !(defined('JIGOSHOP_CHECKOUT') && JIGOSHOP_CHECKOUT)) {
                 $request = '';
                 $this->set_error_message('Please proceed to checkout to get shipping estimates');
             } else {
                 // create request input for shipping service
                 $request = $this->create_mail_request($current_service);
             }
             if ($request) {
                 // send to shipping server and get xml back
                 $post_response = $this->send_to_shipping_server($request);
                 // convert xml into an array
                 $xml_response = $this->convert_xml_to_array($post_response);
                 // sums up the rates from flattened array, and generates amounts.
                 $rate = $this->retrieve_rate_from_response($xml_response);
                 if ($this->has_error()) {
                     jigoshop_log($xml_response, 'jigoshop_calculable_shipping');
                 }
                 $this->add_rate($rate, $current_service);
             }
         }
     } else {
         if (!jigoshop_shipping::show_shipping_calculator() && !(defined('JIGOSHOP_CHECKOUT') && JIGOSHOP_CHECKOUT)) {
             $request = '';
             $this->set_error_message('Please proceed to checkout to get shipping estimates');
         } else {
             // create request input for shipping service
             $request = $this->create_mail_request();
         }
         if ($request) {
             // send to shipping server and get xml back
             $post_response = $this->send_to_shipping_server($request);
             // convert xml into an array
             $xml_response = $this->convert_xml_to_array($post_response);
             // services are obtained from response
             $services = $this->get_services_from_response($xml_response);
             if (empty($services)) {
                 jigoshop_log($xml_response, 'jigoshop_calculable_shipping');
             }
             foreach ($services as $current_service) {
                 $rate = $this->retrieve_rate_from_response($xml_response, $current_service);
                 $this->add_rate($rate, $current_service);
             }
         }
     }
     // service returned an error since no rates were calculated
     if (($this->rates == NULL || !$this->rates) && !$this->has_error()) {
         $this->has_error = true;
     }
 }
Esempio n. 2
0
function jigoshop_cart($atts)
{
    unset(jigoshop_session::instance()->selected_rate_id);
    // Process Discount Codes
    if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) {
        $coupon_code = sanitize_title($_POST['coupon_code']);
        jigoshop_cart::add_discount($coupon_code);
    } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && jigoshop::verify_nonce('cart')) {
        // Update Shipping
        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();
        // chooses the method selected by user.
    }
    // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results.
    jigoshop_cart::calculate_totals();
    $result = jigoshop_cart::check_cart_item_stock();
    if (is_wp_error($result)) {
        jigoshop::add_error($result->get_error_message());
    }
    jigoshop_render('shortcode/cart', array('cart' => jigoshop_cart::get_cart(), 'coupons' => jigoshop_cart::get_coupons()));
}
 function receipt_kaznachey($order_id)
 {
     $this->kaznachey_init();
     $order = new jigoshop_order($order_id);
     $sum = $qty = 0;
     foreach ($order->items as $item) {
         $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($item['id']), 'large');
         $request['Products'][] = array("ProductId" => $item['id'], "ProductName" => $item['name'], "ProductPrice" => $item['cost'], "ProductItemsNum" => $item['qty'], "ImageUrl" => isset($thumb[0]) ? $thumb[0] : '');
         $sum += $item['cost'] * $item['qty'];
         $qty += $item['qty'];
     }
     // Доставка
     if (jigoshop_shipping::is_enabled()) {
         if ($order->order_shipping > 0) {
             $request['Products'][] = array("ProductId" => 1, "ProductName" => 'Доставка', "ProductPrice" => $order->order_shipping, "ProductItemsNum" => 1, "ImageUrl" => '');
             $sum += $order->order_shipping;
             $qty += 1;
         }
     }
     $request["MerchantGuid"] = $this->merchantGuid;
     $request['SelectedPaySystemId'] = $_COOKIE['cc_types'] ? $_COOKIE['cc_types'] : $this->GetMerchnatInfo(false, true);
     $request['Currency'] = $this->currency;
     $request['Language'] = $this->language;
     $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
     $request['PaymentDetails'] = array("EMail" => $order->billing_email, "PhoneNumber" => $order->billing_phone, "MerchantInternalPaymentId" => $order->id, "MerchantInternalUserId" => $order->user_id, "StatusUrl" => add_query_arg('key', $order->order_key, add_query_arg('order', $order->id, get_permalink($checkout_redirect))), "ReturnUrl" => get_permalink($checkout_redirect), "CustomMerchantInfo" => "", "BuyerCountry" => $order->billing_country, "BuyerFirstname" => $order->billing_first_name, "BuyerPatronymic" => '', "BuyerLastname" => $order->billing_last_name, "BuyerStreet" => $order->billing_address_1, "BuyerZone" => $order->billing_state, "BuyerZip" => '', "BuyerCity" => $order->billing_city, "DeliveryFirstname" => $order->shipping_first_name, "DeliveryPatronymic" => '', "DeliveryLastname" => $order->shipping_last_name, "DeliveryZip" => '', "DeliveryCountry" => $order->shipping_country, "DeliveryStreet" => $order->shipping_address_1, "DeliveryCity" => $order->shipping_city, "DeliveryZone" => $order->shipping_state);
     $request["Signature"] = md5(strtoupper($this->merchantGuid) . number_format($sum, 2, ".", "") . $request["SelectedPaySystemId"] . $request["PaymentDetails"]["EMail"] . $request["PaymentDetails"]["PhoneNumber"] . $request["PaymentDetails"]["MerchantInternalUserId"] . $request["PaymentDetails"]["MerchantInternalPaymentId"] . strtoupper($request["Language"]) . strtoupper($request["Currency"]) . strtoupper($this->merchnatSecretKey));
     $response = $this->sendRequestKaznachey(json_encode($request), "CreatePaymentEx");
     $result = json_decode($response, true);
     if ($result['ErrorCode'] != 0) {
         wp_redirect(home_url());
         exit;
     }
     echo base64_decode($result["ExternalForm"]);
     jigoshop_cart::empty_cart();
     exit;
 }
Esempio n. 4
0
function jigoshop_init()
{
    // Override default translations with custom .mo's found in wp-content/languages/jigoshop first.
    load_textdomain('jigoshop', WP_LANG_DIR . '/jigoshop/jigoshop-' . get_locale() . '.mo');
    load_plugin_textdomain('jigoshop', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'jigoshop_admin_bar_links');
    do_action('before_jigoshop_init');
    // instantiate options -after- loading text domains
    $options = Jigoshop_Base::get_options();
    jigoshop_post_type();
    // register taxonomies
    new jigoshop_cron();
    // -after- text domains and Options instantiation allows settings translations
    jigoshop_set_image_sizes();
    // called -after- our Options are loaded
    // add Singletons here so that the taxonomies are loaded before calling them.
    jigoshop_session::instance();
    // Start sessions if they aren't already
    jigoshop::instance();
    // Utility functions, uses sessions
    jigoshop_customer::instance();
    // Customer class, sorts session data such as location
    // Jigoshop will instantiate gateways and shipping methods on this same 'init' action hook
    // with a very low priority to ensure text domains are loaded first prior to installing any external options
    jigoshop_shipping::instance();
    // Shipping class. loads shipping methods
    jigoshop_payment_gateways::instance();
    // Payment gateways class. loads payment methods
    jigoshop_cart::instance();
    // Cart class, uses sessions
    add_filter('mce_external_plugins', 'jigoshop_register_shortcode_editor');
    add_filter('mce_buttons', 'jigoshop_register_shortcode_buttons');
    if (!is_admin()) {
        /* Catalog Filters */
        add_filter('loop-shop-query', create_function('', 'return array("orderby" => "' . $options->get('jigoshop_catalog_sort_orderby') . '","order" => "' . $options->get('jigoshop_catalog_sort_direction') . '");'));
        add_filter('loop_shop_columns', create_function('', 'return ' . $options->get('jigoshop_catalog_columns') . ';'));
        add_filter('loop_shop_per_page', create_function('', 'return ' . $options->get('jigoshop_catalog_per_page') . ';'));
        jigoshop_catalog_query::instance();
        // front end queries class
        jigoshop_request_api::instance();
        // front end request api for URL's
    }
    jigoshop_roles_init();
    do_action('jigoshop_initialize_plugins');
}
Esempio n. 5
0
					<?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 
        do_action('jigoshop_after_cart_totals');
    } else {
        echo '<p>' . __(jigoshop_shipping::get_shipping_error_message(), 'jigoshop') . '</p>';
    }
    ?>
	</div>
	<?php 
    do_action('jigoshop_before_shipping_calculator');
    jigoshop_shipping_calculator();
    do_action('jigoshop_after_shipping_calculator');
    ?>
</div>
<?php 
}
Esempio n. 6
0
	function calculate_shipping() {
		
		if (self::$enabled=='yes') :
		
			self::$shipping_total = 0;
			self::$shipping_tax = 0;
			self::$shipping_label = null;
			$_cheapest_fee = '';
			$_cheapest_method = '';
			if (isset($_SESSION['_chosen_method_id'])) $chosen_method = $_SESSION['_chosen_method_id']; else $chosen_method = '';
			$calc_cheapest = false;
			
			if (!$chosen_method || empty($chosen_method)) $calc_cheapest = true;
			
			self::reset_shipping_methods();
			
			$_available_methods = self::get_available_shipping_methods();
			
			if (sizeof($_available_methods)>0) :
			
				foreach ($_available_methods as $method) :
					
					$method->calculate_shipping();
					$fee = $method->shipping_total;
					if ($fee < $_cheapest_fee || !is_numeric($_cheapest_fee)) :
						$_cheapest_fee = $fee;
						$_cheapest_method = $method->id;
					endif;
					
				endforeach;
				
				// Default to cheapest
				if ($calc_cheapest || !isset($_available_methods[$chosen_method])) :
					$chosen_method = $_cheapest_method;
				endif;
				
				if ($chosen_method) :
					
					$_available_methods[$chosen_method]->choose();
					self::$shipping_total 	= $_available_methods[$chosen_method]->shipping_total;
					self::$shipping_tax 	= $_available_methods[$chosen_method]->shipping_tax;
					self::$shipping_label 	= $_available_methods[$chosen_method]->title;
					
				endif;
			endif;

		endif;
		
	}
    public function format_option_for_display($item)
    {
        $options = Jigoshop_Base::get_options();
        if (!isset($item['id'])) {
            return '';
        }
        // ensure we have an id to work with
        $display = "";
        // each item builds it's output into this and it's returned for echoing
        $class = "";
        if (isset($item['class'])) {
            $class = $item['class'];
        }
        // display a tooltip if there is one in it's own table data element before the item to display
        $display .= '<td class="jigoshop-tooltips">';
        if (!empty($item['tip'])) {
            $display .= '<a href="#" tip="' . esc_attr($item['tip']) . '" class="tips" tabindex="99"></a>';
        }
        $display .= '</td><td class="forminp">';
        $disabled = '';
        $disabledItems = array();
        if (isset($item['extra']) && isset($item['extra']['disabled'])) {
            if ($item['extra']['disabled'] === true) {
                $disabled = ' disabled';
            } else {
                if (is_array($item['extra']['disabled'])) {
                    $disabledItems = $item['extra']['disabled'];
                }
            }
        }
        /*
         *  work off the option type and format output for display for each type
         */
        switch ($item['type']) {
            case 'user_defined':
                if (isset($item['display'])) {
                    if (is_callable($item['display'], true)) {
                        $display .= call_user_func($item['display']);
                    }
                }
                break;
            case 'default_gateway':
                $id = $item['id'];
                $display .= '<select id="' . $id . '" class="jigoshop-input jigoshop-select ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $id . ']"' . $disabled . ' >';
                $gateways = jigoshop_payment_gateways::get_available_payment_gateways();
                foreach ($gateways as $slug => $gateway) {
                    $display .= '<option value="' . esc_attr($slug) . '" ' . selected($options->get($id), $slug, false) . disabled(in_array($id, $disabledItems, false)) . ' />' . $gateway->title . '</option>';
                }
                $display .= '</select>';
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '250px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'gateway_options':
                foreach (jigoshop_payment_gateways::payment_gateways() as $gateway) {
                    $gateway->admin_options();
                }
                break;
            case 'shipping_options':
                foreach (jigoshop_shipping::get_all_methods() as $shipping_method) {
                    $shipping_method->admin_options();
                }
                break;
            case 'tax_rates':
                $display .= $this->format_tax_rates_for_display($item);
                break;
            case 'single_select_page':
                $page_setting = (int) $options->get($item['id']);
                $args = array('name' => JIGOSHOP_OPTIONS . '[' . $item['id'] . ']', 'id' => $item['id'], 'sort_order' => 'ASC', 'echo' => 0, 'selected' => $page_setting);
                if (isset($item['extra'])) {
                    $args = wp_parse_args($item['extra'], $args);
                }
                $display .= wp_dropdown_pages($args);
                $parts = explode('<select', $display);
                $id = $item['id'];
                $display = $parts[0] . '<select id="' . $id . '" class="' . $class . '"' . $parts[1];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '250px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'single_select_country':
                $country_setting = (string) $options->get($item['id']);
                $add_empty = false;
                if (isset($item['options']['add_empty']) && $item['options']['add_empty']) {
                    $add_empty = true;
                }
                if (strstr($country_setting, ':')) {
                    $temp = explode(':', $country_setting);
                    $country = current($temp);
                    $state = end($temp);
                } else {
                    $country = $country_setting;
                    $state = '*';
                }
                $id = $item['id'];
                $display .= '<select id="' . $id . '" class="single_select_country ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"' . $disabled . '>';
                $display .= jigoshop_countries::country_dropdown_options($country, $state, true, false, false, $add_empty);
                $display .= '</select>';
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '500px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'multi_select_countries':
                $countries = jigoshop_countries::get_countries();
                $selections = (array) $options->get($item['id']);
                $display .= '<select multiple="multiple" id="' . $item['id'] . '" class="jigoshop-input jigoshop-select ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . '][]"' . $disabled . '>';
                foreach ($countries as $key => $val) {
                    $display .= '<option value="' . esc_attr($key) . '" ' . selected(in_array($key, $selections), true, false) . disabled(in_array($key, $disabledItems, false)) . ' />' . $val . '</option>';
                }
                $display .= '</select>';
                $id = $item['id'];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '500px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            case 'button':
                if (isset($item['extra'])) {
                    $display .= '<a id="' . $item['id'] . '" class="button ' . $class . '" href="' . esc_attr($item['extra']) . '">' . esc_attr($item['desc']) . '</a>';
                }
                $item['desc'] = '';
                // temporarily remove it so it doesn't display twice
                break;
            case 'decimal':
                // decimal numbers are positive or negative 0-9 inclusive, may include decimal
                $display .= '<input	id="' . $item['id'] . '" class="jigoshop-input jigoshop-text ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="number" step="any" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'integer':
                // integer numbers are positive or negative 0-9 inclusive
            // integer numbers are positive or negative 0-9 inclusive
            case 'natural':
                // natural numbers are positive 0-9 inclusive
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-text ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="number" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'text':
                // any character sequence
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-text ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="20" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'midtext':
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-text ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'longtext':
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-text ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="80" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'email':
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-text jigoshop-email ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="text" size="40" value="' . esc_attr($options->get($item['id'])) . '"' . $disabled . ' />';
                break;
            case 'codeblock':
            case 'textarea':
                $cols = '60';
                if (isset($item['choices'])) {
                    $ta_options = $item['choices'];
                    if (isset($ta_options['cols'])) {
                        $cols = $ta_options['cols'];
                    }
                }
                $ta_value = stripslashes($options->get($item['id']));
                $display .= '<textarea id="' . $item['id'] . '" class="jigoshop-input jigoshop-textarea ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']" cols="' . $cols . '" rows="4"' . $disabled . '>' . esc_textarea($ta_value) . '</textarea>';
                break;
            case "radio":
                // default to horizontal display of choices ( 'horizontal' may or may not be defined )
                if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) {
                    $display .= '<div class="jigoshop-radio-horz">';
                    foreach ($item['choices'] as $option => $name) {
                        $display .= '<input class="jigoshop-input jigoshop-radio ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
							id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . '
							/><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label>';
                    }
                    $display .= '</div>';
                } else {
                    if (isset($item['extra']) && in_array('vertical', $item['extra'])) {
                        $display .= '<ul class="jigoshop-radio-vert">';
                        foreach ($item['choices'] as $option => $name) {
                            $display .= '<li><input class="jigoshop-input jigoshop-radio ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
							id="' . $item['id'] . '[' . $option . ']" type="radio" value="' . $option . '" ' . checked($options->get($item['id']), $option, false) . disabled(in_array($option, $disabledItems), true, false) . '
							/><label for="' . $item['id'] . '[' . $option . ']">' . $name . '</label></li>';
                        }
                        $display .= '</ul>';
                    }
                }
                break;
            case 'checkbox':
                $display .= '<span class="jigoshop-container"><input id="' . $item['id'] . '" type="checkbox" class="jigoshop-input jigoshop-checkbox ' . $class . '"
					name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']" ' . checked($options->get($item['id']), 'yes', false) . $disabled . '
					/><label for="' . $item['id'] . '">' . $item['name'] . '</label></span>';
                break;
            case 'multicheck':
                $multi_stored = $options->get($item['id']);
                // default to horizontal display of choices ( 'horizontal' may or may not be defined )
                if (!isset($item['extra']) || !in_array('vertical', $item['extra'])) {
                    $display .= '<div class="jigoshop-multi-checkbox-horz ' . $class . '">';
                    foreach ($item['choices'] as $key => $option) {
                        $display .= '<input id="' . $item['id'] . '_' . $key . '" class="jigoshop-input" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . '][' . $key . ']"
							type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label>';
                    }
                    $display .= '</div>';
                } else {
                    if (isset($item['extra']) && in_array('vertical', $item['extra'])) {
                        $display .= '<ul class="jigoshop-multi-checkbox-vert ' . $class . '">';
                        foreach ($item['choices'] as $key => $option) {
                            $display .= '<li><input id="' . $item['id'] . '_' . $key . '" class="jigoshop-input" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . '][' . $key . ']"
							type="checkbox" ' . checked($multi_stored[$key], true, false) . disabled(in_array($key, $disabledItems, false)) . ' /> <label for="' . $item['id'] . '_' . $key . '">' . $option . '</label></li>';
                        }
                        $display .= '</ul>';
                    }
                }
                break;
            case 'range':
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input jigoshop-range ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']"
					type="range" min="' . $item['extra']['min'] . '" max="' . $item['extra']['max'] . '" step="' . $item['extra']['step'] . '"
					value="' . $options->get($item['id']) . '"' . $disabled . ' />';
                break;
            case 'number':
                $display .= '<input id="' . $item['id'] . '" class="jigoshop-input ' . $class . '" name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']" type="number" value="' . $options->get($item['id']) . '"';
                if (isset($item['extra']['min'])) {
                    $display .= ' min="' . $item['extra']['min'] . '"';
                }
                if (isset($item['extra']['max'])) {
                    $display .= ' max="' . $item['extra']['max'] . '"';
                }
                if (isset($item['extra']['step'])) {
                    $display .= ' step="' . $item['extra']['step'] . '"';
                }
                $display .= $disabled . ' />';
                break;
            case 'select':
                $multiple = !empty($item['multiple']) && $item['multiple'] == true ? 'multiple="multiple"' : "";
                $brckt = "";
                $width = 250;
                $selections = (array) $options->get($item['id']);
                if ($item['multiple']) {
                    $brckt = "[]";
                    $width = 500;
                }
                $display .= '<select id="' . $item['id'] . '" class="jigoshop-input jigoshop-select ' . $class . '"
					name="' . JIGOSHOP_OPTIONS . '[' . $item['id'] . ']' . $brckt . '"' . $multiple . $disabled . ' >';
                foreach ($item['choices'] as $value => $label) {
                    if (is_array($label)) {
                        $display .= '<optgroup label="' . $value . '">';
                        foreach ($label as $subValue => $subLabel) {
                            $display .= '<option value="' . esc_attr($subValue) . '" ' . selected(in_array(esc_attr($subValue), $selections), true, false) . disabled(in_array($subValue, $disabledItems), true, false) . ' />' . $subLabel . '</option>';
                        }
                        $display .= '</optgroup>';
                    } else {
                        $display .= '<option value="' . esc_attr($value) . '" ' . selected(in_array(esc_attr($value), $selections), true, false) . disabled(in_array($value, $disabledItems), true, false) . ' />' . $label . '</option>';
                    }
                }
                $display .= '</select>';
                $id = $item['id'];
                ?>
				<script type="text/javascript">
					/*<![CDATA[*/
					jQuery(function($){
						$("#<?php 
                echo $id;
                ?>
").select2({ width: '<?php 
                echo $width;
                ?>
px' });
					});
					/*]]>*/
				</script>
				<?php 
                break;
            default:
                jigoshop_log("UNKOWN _type_ in Options parsing");
                jigoshop_log($item);
        }
        if ($item['type'] != 'tab') {
            if (empty($item['desc'])) {
                $explain_value = '';
            } else {
                $explain_value = $item['desc'];
            }
            $display .= '<div class="jigoshop-explain"><small>' . $explain_value . '</small></div></td>';
        }
        return $display;
    }
 public static function reset_shipping()
 {
     self::$shipping_total = 0;
     self::$shipping_tax = 0;
     self::$shipping_label = null;
     self::$shipping_error_message = null;
 }
Esempio n. 9
0
function jigoshop_process_shop_order_meta($post_id)
{
    $jigoshop_options = Jigoshop_Base::get_options();
    $jigoshop_errors = array();
    $order = new jigoshop_order($post_id);
    // Get old data + attributes
    $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true));
    //Get old order items
    $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true));
    // Add/Replace data to array
    $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_euvatno', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state');
    $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax');
    /* Pre-fill the customer addresses */
    foreach ($customerDetails as $key) {
        $order_fields[] = $key;
        /* Checks if this is a new order from "Add Order" button */
        if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) {
            $data[$key] = get_user_meta($_POST['customer_user'], $key, true);
        }
    }
    //Check EUVAT Field
    if (!empty($data['billing_euvatno']) && !empty($data['billing_country'])) {
        $data['billing_euvatno'] = str_replace(' ', '', $data['billing_euvatno']);
    }
    //run stripslashes on all valid fields
    foreach ($order_fields as $field_name) {
        if (isset($_POST[$field_name])) {
            $data[$field_name] = stripslashes($_POST[$field_name]);
        }
    }
    // Sanitize numeric values
    $data['order_total'] = jigoshop_sanitize_num($data['order_total']);
    $data['order_subtotal'] = jigoshop_sanitize_num($data['order_subtotal']);
    // if a shipping or payment methods has changed, update the method title for pretty display
    if (isset($_POST['shipping_method'])) {
        $data['shipping_service'] = '';
        $shipping_methods = jigoshop_shipping::get_all_methods();
        if (!empty($shipping_methods)) {
            foreach ($shipping_methods as $method) {
                if ($_POST['shipping_method'] == $method->id) {
                    $data['shipping_service'] = $method->title;
                }
            }
        }
    }
    if (isset($_POST['payment_method'])) {
        $data['payment_method_title'] = '';
        $payment_methods = jigoshop_payment_gateways::get_available_payment_gateways();
        if (!empty($payment_methods)) {
            foreach ($payment_methods as $method) {
                if ($_POST['payment_method'] == $method->id) {
                    $data['payment_method_title'] = $method->title;
                }
            }
        }
    }
    // if total tax has been modified from order tax, then create a customized tax array
    // just for the order. At this point, we no longer know about multiple tax classes.
    // Even if we used the old tax array data, we still don't know how to break down
    // the amounts since they're customized.
    if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) {
        $new_tax = $data['order_tax_total'];
        $data['order_tax'] = jigoshop_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null);
    }
    // Customer
    update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']);
    // Order items
    $order_items = array();
    if (isset($_POST['item_id'])) {
        $item_id = $_POST['item_id'];
        $item_variation = $_POST['item_variation_id'];
        $item_name = $_POST['item_name'];
        $item_quantity = $_POST['item_quantity'];
        $item_cost = $_POST['item_cost'];
        $item_tax_rate = $_POST['item_tax_rate'];
        for ($i = 0; $i < count($item_id); $i++) {
            if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) {
                continue;
            }
            $variation_id = '';
            $variation = '';
            if (!empty($item_variation[$i])) {
                $variation_id = (int) $item_variation[$i];
                // if this is a variation, we should check if it is an old one
                // and copy the 'variation' field describing details of variation
                foreach ($old_order_items as $old_item_index => $old_item) {
                    if ($old_item['variation_id'] == $variation_id) {
                        $variation = $old_item['variation'];
                        unset($old_order_items[$old_item_index]);
                        break;
                    }
                }
                // override variation with values from $_POST
                if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) {
                    foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) {
                        $variation[$var_key] = $var_value;
                    }
                }
            }
            $cost_inc_tax = $jigoshop_options->get('jigoshop_prices_include_tax') == 'yes' ? number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', '') : -1;
            $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) jigowatt_clean($item_tax_rate[$i]), 4, '.', '')));
        }
    }
    // Process custom attributes added with "jigoshop_order_data_panels"
    $data = apply_filters("jigoshop_order_data_save", $data, $post_id);
    // Save
    update_post_meta($post_id, 'order_data', $data);
    update_post_meta($post_id, 'order_items', $order_items);
    // Order status
    $order->update_status($_POST['order_status']);
    // Handle button actions
    if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) {
        $order->add_order_note(__('Manually reducing stock.', 'jigoshop'));
        foreach ($order_items as $order_item) {
            $_product = $order->get_product_from_item($order_item);
            if ($_product->exists) {
                if ($_product->managing_stock()) {
                    $old_stock = $_product->stock;
                    $new_quantity = $_product->reduce_stock($order_item['qty']);
                    $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity));
                    if ($new_quantity < 0) {
                        if ($old_stock < 0) {
                            $backorder_qty = $order_item['qty'];
                        } else {
                            $backorder_qty = $old_stock - $order_item['qty'];
                        }
                        do_action('jigoshop_product_on_backorder_notification', $post_id, $_product, $backorder_qty);
                    }
                    // stock status notifications
                    if ($jigoshop_options->get('jigoshop_notify_no_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= 0 && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= $new_quantity) {
                        do_action('jigoshop_no_stock_notification', $_product);
                    } else {
                        if ($jigoshop_options->get('jigoshop_notify_low_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_low_stock_amount') >= $new_quantity) {
                            do_action('jigoshop_low_stock_notification', $_product);
                        }
                    }
                }
            } else {
                $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name']));
            }
        }
        $order->add_order_note(__('Manual stock reduction complete.', 'jigoshop'));
    } else {
        if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) {
            $order->add_order_note(__('Manually restoring stock.', 'jigoshop'));
            foreach ($order_items as $order_item) {
                $_product = $order->get_product_from_item($order_item);
                if ($_product->exists) {
                    if ($_product->managing_stock()) {
                        $old_stock = $_product->stock;
                        $new_quantity = $_product->increase_stock($order_item['qty']);
                        $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity));
                    }
                } else {
                    $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name']));
                }
            }
            $order->add_order_note(__('Manual stock restore complete.', 'jigoshop'));
        } else {
            if (isset($_POST['invoice']) && $_POST['invoice']) {
                // Mail link to customer
                jigoshop_send_customer_invoice($order->id);
            }
        }
    }
    // Error Handling
    if (count($jigoshop_errors) > 0) {
        $jigoshop_options->set('jigoshop_errors', $jigoshop_errors);
    }
}
Esempio n. 10
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		
}
Esempio n. 11
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 
}
Esempio n. 12
0
" <?php 
            selected($method->is_rate_selected($i));
            ?>
>
						<?php 
            echo $service;
            ?>
 &ndash; <?php 
            echo $price > 0 ? jigoshop_price($price, array('ex_tax_label' => (int) $is_taxed)) : __('Free', 'jigoshop');
            ?>
					</option>
				<?php 
        }
        ?>
			<?php 
    }
    ?>
		</select>
		<?php 
} else {
    ?>
			<p><?php 
    echo __(jigoshop_shipping::get_shipping_error_message(), 'jigoshop');
    ?>
</p>
		<?php 
}
?>
	</td>
</tr>
	/** Process the checkout after the confirm order button is pressed */
	function process_checkout() {
	
		global $wpdb;
		
		do_action('jigoshop_before_checkout_process');
		
		if (isset($_POST) && $_POST && !isset($_POST['login'])) :

			jigoshop_cart::calculate_totals();
			
			jigoshop::verify_nonce('process_checkout');
			
			if (sizeof(jigoshop_cart::$cart_contents)==0) :
				jigoshop::add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>','jigoshop'), home_url()) );
			endif;
						
			// Checkout fields
			$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['shipping_method'] = isset($_POST['shipping_method']) ? jigowatt_clean($_POST['shipping_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['createaccount'] = isset($_POST['createaccount']) ? jigowatt_clean($_POST['createaccount']) : '';
			$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::ship_to_billing_address_only()) $this->posted['shiptobilling'] = 'true';
			
			// Billing Information
			foreach ($this->billing_fields as $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;
				endswitch;
				
				// Required
				if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (billing) is a required field.','jigoshop') );
	
				// 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') ); endif;
					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') ); endif;
					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'] );
						endif;
					break;
				endswitch;
				
			endforeach;
			
			// Shipping Information
			if (jigoshop_cart::needs_shipping() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) :
				
				foreach ($this->shipping_fields as $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;
					endswitch;
					
					// Required
					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']], $this->posted['shipping-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']], $this->posted['shipping-country'] );
							endif;
						break;
					endswitch;
					
				endforeach;
			
			endif;

			if (is_user_logged_in()) :
				$this->creating_account = false;
			elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) :
				$this->creating_account = true;
			elseif ($this->must_create_account) :
				$this->creating_account = true;
			else :
				$this->creating_account = false;
			endif;
			
			if ($this->creating_account && !$user_id) :
			
				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') );
				endif;
				
				// 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') );
				endif;
			endif;
			
			// Terms
			if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && get_option('jigoshop_terms_page_id')>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') );
				endif;	
			
			endif;	
			
			if (jigoshop_cart::needs_payment()) :
				// Payment Method
				$available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
				if (!isset($available_gateways[$this->posted['payment_method']])) :
					jigoshop::add_error( __('Invalid payment method.','jigoshop') );
				else :
					// Payment Method Field Validation
					$available_gateways[$this->posted['payment_method']]->validate_fields();
				endif;
			endif;
					
			if (!isset($_POST['update_totals']) && jigoshop::error_count()==0) :
				
				$user_id = get_current_user_id();
				
				while (1) :
					
					// Create customer account and log them in
					if ($this->creating_account && !$user_id) :
				
						$reg_errors = new WP_Error();
						do_action('register_post', $this->posted['billing-email'], $this->posted['billing-email'], $reg_errors);
						$errors = apply_filters( 'registration_errors', $reg_errors, $this->posted['billing-email'], $this->posted['billing-email'] );
				
		                // if there are no errors, let's create the user account
						if ( !$reg_errors->get_error_code() ) :
		
			                $user_pass = $this->posted['account-password'];
			                $user_id = wp_create_user( $this->posted['account-username'], $user_pass, $this->posted['billing-email'] );
			                if ( !$user_id ) {
			                	jigoshop::add_error( sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'jigoshop'), get_option('admin_email')));
			                    break;
			                }
		
		                    // Change role
		                    wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ;
		
		                    // send the user a confirmation and their login details
		                    wp_new_user_notification( $user_id, $user_pass );
		
		                    // set the WP login cookie
		                    $secure_cookie = is_ssl() ? true : false;
		                    wp_set_auth_cookie($user_id, true, $secure_cookie);
						
						else :
							jigoshop::add_error( $reg_errors->get_error_message() );
		                	break;                    
						endif;
						
					endif;

					// Get shipping/billing
					if ( !empty($this->posted['shiptobilling']) ) :
					
						$shipping_first_name = $this->posted['billing-first_name'];
						$shipping_last_name = $this->posted['billing-last_name'];
						$shipping_company = $this->posted['billing-company'];
						$shipping_address_1 = $this->posted['billing-address'];
						$shipping_address_2 = $this->posted['billing-address-2'];
						$shipping_city = $this->posted['billing-city'];							
						$shipping_state = $this->posted['billing-state'];
						$shipping_postcode = $this->posted['billing-postcode'];	
						$shipping_country = $this->posted['billing-country'];
						
					elseif ( jigoshop_cart::needs_shipping() ) :
								
						$shipping_first_name = $this->posted['shipping-first_name'];
						$shipping_last_name = $this->posted['shipping-last_name'];
						$shipping_company = $this->posted['shipping-company'];
						$shipping_address_1 = $this->posted['shipping-address'];
						$shipping_address_2 = $this->posted['shipping-address-2'];
						$shipping_city = $this->posted['shipping-city'];							
						$shipping_state = $this->posted['shipping-state'];
						$shipping_postcode = $this->posted['shipping-postcode'];	
						$shipping_country = $this->posted['shipping-country'];
						
					endif;
					
					// Save billing/shipping to user meta fields
					if ($user_id>0) :
						update_user_meta( $user_id, 'billing-first_name', $this->posted['billing-first_name'] );
						update_user_meta( $user_id, 'billing-last_name', $this->posted['billing-last_name'] );
						update_user_meta( $user_id, 'billing-company', $this->posted['billing-company'] );
						update_user_meta( $user_id, 'billing-email', $this->posted['billing-email'] );
						update_user_meta( $user_id, 'billing-address', $this->posted['billing-address'] );
						update_user_meta( $user_id, 'billing-address-2', $this->posted['billing-address-2'] );
						update_user_meta( $user_id, 'billing-city', $this->posted['billing-city'] );
						update_user_meta( $user_id, 'billing-postcode', $this->posted['billing-postcode'] );
						update_user_meta( $user_id, 'billing-country', $this->posted['billing-country'] );
						update_user_meta( $user_id, 'billing-state', $this->posted['billing-state'] );
						update_user_meta( $user_id, 'billing-phone', $this->posted['billing-phone'] );

						if ( empty($this->posted['shiptobilling']) && jigoshop_cart::needs_shipping() ) :
							update_user_meta( $user_id, 'shipping-first_name', $this->posted['shipping-first_name'] );
							update_user_meta( $user_id, 'shipping-last_name', $this->posted['shipping-last_name'] );
							update_user_meta( $user_id, 'shipping-company', $this->posted['shipping-company'] );
							update_user_meta( $user_id, 'shipping-address', $this->posted['shipping-address'] );
							update_user_meta( $user_id, 'shipping-address-2', $this->posted['shipping-address-2'] );
							update_user_meta( $user_id, 'shipping-city', $this->posted['shipping-city'] );
							update_user_meta( $user_id, 'shipping-postcode', $this->posted['shipping-postcode'] );
							update_user_meta( $user_id, 'shipping-country', $this->posted['shipping-country'] );
							update_user_meta( $user_id, 'shipping-state', $this->posted['shipping-state'] );
						elseif ( $this->posted['shiptobilling'] && jigoshop_cart::needs_shipping() ) :
							update_user_meta( $user_id, 'shipping-first_name', $this->posted['billing-first_name'] );
							update_user_meta( $user_id, 'shipping-last_name', $this->posted['billing-last_name'] );
							update_user_meta( $user_id, 'shipping-company', $this->posted['billing-company'] );
							update_user_meta( $user_id, 'shipping-address', $this->posted['billing-address'] );
							update_user_meta( $user_id, 'shipping-address-2', $this->posted['billing-address-2'] );
							update_user_meta( $user_id, 'shipping-city', $this->posted['billing-city'] );
							update_user_meta( $user_id, 'shipping-postcode', $this->posted['billing-postcode'] );
							update_user_meta( $user_id, 'shipping-country', $this->posted['billing-country'] );
							update_user_meta( $user_id, 'shipping-state', $this->posted['billing-state'] );
						endif;
						
					endif;
					
					// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time.
					
					$_tax = new jigoshop_tax();
					
					$order_data = array(
						'post_type' => 'shop_order',
						'post_title' => 'Order &ndash; '.date('F j, Y @ h:i A'),
						'post_status' => 'publish',
						'post_excerpt' => $this->posted['order_comments'],
						'post_author' => 1
					);
					
					// Order meta data
					$data = array();
					$data['billing_first_name'] 	= $this->posted['billing-first_name'];
					$data['billing_last_name'] 		= $this->posted['billing-last_name'];
					$data['billing_company'] 		= $this->posted['billing-company'];
					$data['billing_address_1'] 		= $this->posted['billing-address'];
					$data['billing_address_2'] 		= $this->posted['billing-address-2'];
					$data['billing_city'] 			= $this->posted['billing-city'];
					$data['billing_postcode'] 		= $this->posted['billing-postcode'];
					$data['billing_country'] 		= $this->posted['billing-country'];
					$data['billing_state'] 			= $this->posted['billing-state'];
					$data['billing_email']			= $this->posted['billing-email'];
					$data['billing_phone']			= $this->posted['billing-phone'];
					$data['shipping_first_name'] 	= $shipping_first_name;
					$data['shipping_last_name'] 	= $shipping_last_name;
					$data['shipping_company']	 	= $shipping_company;
					$data['shipping_address_1']		= $shipping_address_1;
					$data['shipping_address_2']		= $shipping_address_2;
					$data['shipping_city']			= $shipping_city;
					$data['shipping_postcode']		= $shipping_postcode;
					$data['shipping_country']		= $shipping_country;
					$data['shipping_state']			= $shipping_state;
					$data['shipping_method']		= $this->posted['shipping_method'];
					$data['payment_method']			= $this->posted['payment_method'];
					$data['order_subtotal']			= number_format(jigoshop_cart::$subtotal_ex_tax, 2, '.', '');
					$data['order_shipping']			= number_format(jigoshop_cart::$shipping_total, 2, '.', '');
					$data['order_discount']			= number_format(jigoshop_cart::$discount_total, 2, '.', '');
					$data['order_tax']				= number_format(jigoshop_cart::$tax_total, 2, '.', '');
					$data['order_shipping_tax']		= number_format(jigoshop_cart::$shipping_tax_total, 2, '.', '');
					$data['order_total']			= number_format(jigoshop_cart::$total, 2, '.', '');
					
					// Cart items
					$order_items = array();
					
					foreach (jigoshop_cart::$cart_contents as $item_id => $values) :
						
						$_product = $values['data'];
			
						// Calc item tax to store
						$rate = '';
						if ( $_product->is_taxable()) :
							$rate = $_tax->get_rate( $_product->data['tax_class'] );
						endif;
						
						$order_items[] = array(
					 		'id' 		=> $item_id,
					 		'name' 		=> $_product->get_title(),
					 		'qty' 		=> (int) $values['quantity'],
					 		'cost' 		=> $_product->get_price_excluding_tax(),
					 		'taxrate' 	=> $rate
					 	);
					 	
					 	// Check stock levels
					 	if ($_product->managing_stock()) :
							if (!$_product->is_in_stock() || !$_product->has_enough_stock( $values['quantity'] )) :
								
								jigoshop::add_error( sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) );
		                		break;
								
							endif;
						else :
						
							if (!$_product->is_in_stock()) :
							
								jigoshop::add_error( sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologise for any inconvenience caused.', 'jigoshop'), $_product->get_title() ) );
		                		break;

							endif;
							
						endif;
					 	
					endforeach;
					
					if (jigoshop::error_count()>0) break;
					
					// Insert or update the post data
					if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) :
						
						$order_id = (int) $_SESSION['order_awaiting_payment'];
						$order_data['ID'] = $order_id;
						wp_update_post( $order_data );
					
					else :
						$order_id = wp_insert_post( $order_data );
						
						if (is_wp_error($order_id)) :
							jigoshop::add_error( 'Error: Unable to create order. Please try again.' );
			                break;
						endif;
					endif;

					// Update post meta
					update_post_meta( $order_id, 'order_data', $data );
					update_post_meta( $order_id, 'order_key', uniqid('order_') );
					update_post_meta( $order_id, 'customer_user', (int) $user_id );
					update_post_meta( $order_id, 'order_items', $order_items );
					wp_set_object_terms( $order_id, 'pending', 'shop_order_status' );
					
					$order = &new jigoshop_order($order_id);
					
					// Inserted successfully 
					do_action('jigoshop_new_order', $order_id);

					if (jigoshop_cart::needs_payment()) :
						
						// Store Order ID in session so it can be re-used after payment failure
						$_SESSION['order_awaiting_payment'] = $order_id;
					
						// Process Payment
						$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );
						
						// Redirect to success/confirmation/payment page
						if ($result['result']=='success') :
						
							if (is_ajax()) : 
								ob_clean();
								echo json_encode($result);
								exit;
							else :
								wp_safe_redirect( $result['redirect'] );
								exit;
							endif;
							
						endif;
					
					else :
					
						// No payment was required for order
						$order->payment_complete();
						
						// Empty the Cart
						jigoshop_cart::empty_cart();
						
						// Redirect to success/confirmation/payment page
						if (is_ajax()) : 
							ob_clean();
							echo json_encode( array('redirect'	=> get_permalink(get_option('jigoshop_thanks_page_id'))) );
							exit;
						else :
							wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) );
							exit;
						endif;
						
					endif;
					
					// Break out of loop
					break;
				
				endwhile;
	
			endif;
			
			// If we reached this point then there were errors
			if (is_ajax()) : 
				ob_clean();
				jigoshop::show_messages();
				exit;
			else :
				jigoshop::show_messages();
			endif;
		
		endif;
	}
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;
        }
    }
}
Esempio n. 15
0
	/** calculate totals for the items in the cart */
	public static function calculate_totals() {

		$_tax = &new jigoshop_tax();

		self::$total = 0;
		self::$cart_contents_total = 0;
		self::$cart_contents_total_ex_tax = 0;
		self::$cart_contents_weight = 0;
		self::$cart_contents_count = 0;
		self::$cart_contents_tax = 0;
		self::$tax_total = 0;
		self::$shipping_tax_total = 0;
		self::$subtotal = 0;
		self::$subtotal_ex_tax = 0;
		self::$discount_total = 0;
		self::$shipping_total = 0;
		self::$cart_dl_count = 0;
		if (sizeof(self::$cart_contents)>0) : foreach (self::$cart_contents as $item_id => $values) :
			$_product = $values['data'];
			if ($_product->exists() && $values['quantity']>0) :

				self::$cart_contents_count = self::$cart_contents_count + $values['quantity'];
				// If product is downloadable don't apply to product
				if( $_product->product_type == 'downloadable' ) {
					self::$cart_dl_count = self::$cart_dl_count + $values['quantity'];
				}

				self::$cart_contents_weight = self::$cart_contents_weight + ($_product->get_weight() * $values['quantity']);

				$total_item_price = $_product->get_price() * $values['quantity'] * 100; // Into pounds

				if ( get_option('jigoshop_calc_taxes')=='yes') :

					if ( $_product->is_taxable() ) :

						$rate = $_tax->get_rate( $_product->data['tax_class'] );

						if (get_option('jigoshop_prices_include_tax')=='yes') :

							$tax_amount = $_tax->calc_tax( $total_item_price, $rate, true );

						else :

							$tax_amount = $_tax->calc_tax( $total_item_price, $rate, false );

						endif;

						if (get_option('jigoshop_prices_include_tax')=='yes' && jigoshop_customer::is_customer_outside_base() && defined('JIGOSHOP_CHECKOUT') && JIGOSHOP_CHECKOUT ) :

							/**
							 * Our prices include tax so we need to take the base tax rate into consideration of our shop's country
							 *
							 * Lets get the base rate first
							 */
							$base_rate = $_tax->get_shop_base_rate( $_product->data['tax_class'] );

							// Calc tax for base country
							$base_tax_amount = round($_tax->calc_tax( $total_item_price, $base_rate, true ));

							// Now calc tax for user county (which now excludes tax)
							$tax_amount = round($_tax->calc_tax( ($total_item_price-$base_tax_amount), $rate, false ));

							// Finally, update $total_item_price to reflect tax amounts
							$total_item_price = ($total_item_price - $base_tax_amount + $tax_amount);

						endif;

					endif;

				endif;

				$total_item_price 			= $total_item_price / 100; // Back to pounds
				$tax_amount 				= ( isset($tax_amount) ? $tax_amount : 0 ) / 100; // Back to pounds

				self::$cart_contents_tax = self::$cart_contents_tax + $tax_amount;

				self::$cart_contents_total = self::$cart_contents_total + $total_item_price;
				self::$cart_contents_total_ex_tax = self::$cart_contents_total_ex_tax + ($_product->get_price_excluding_tax() * $values['quantity']);

				// Product Discounts
				if (self::$applied_coupons) foreach (self::$applied_coupons as $code) :
					$coupon = jigoshop_coupons::get_coupon($code);
					if ($coupon['type']=='fixed_product' && in_array($item_id, $coupon['products'])) :
						self::$discount_total = self::$discount_total + ( $coupon['amount'] * $values['quantity'] );
					endif;
				endforeach;

			endif;
		endforeach; endif;

		// Cart Shipping
		if (self::needs_shipping()) jigoshop_shipping::calculate_shipping();

		self::$shipping_total = jigoshop_shipping::$shipping_total;

		self::$shipping_tax_total = jigoshop_shipping::$shipping_tax;

		self::$tax_total = self::$cart_contents_tax;

		// Subtotal
		self::$subtotal_ex_tax = self::$cart_contents_total_ex_tax;
		self::$subtotal = self::$cart_contents_total;

		// Cart Discounts
		if (self::$applied_coupons) foreach (self::$applied_coupons as $code) :
			$coupon = jigoshop_coupons::get_coupon($code);
			if (jigoshop_coupons::is_valid($code)) :

				if ($coupon['type']=='fixed_cart') :
					self::$discount_total = self::$discount_total + $coupon['amount'];
				elseif ($coupon['type']=='percent') :
					self::$discount_total = self::$discount_total + ( self::$subtotal / 100 ) * $coupon['amount'];
				endif;

			endif;
		endforeach;

		// Total
		if (get_option('jigoshop_prices_include_tax')=='yes') :
			self::$total = self::$subtotal + self::$shipping_tax_total - self::$discount_total + jigoshop_shipping::$shipping_total;
		else :
			self::$total = self::$subtotal + self::$tax_total + self::$shipping_tax_total - self::$discount_total + jigoshop_shipping::$shipping_total;
		endif;

		if (self::$total < 0) self::$total = 0;
	}
Esempio n. 16
0
 /**
  * Generate the paypal button link
  *
  * @param int $order_id
  * @return string
  */
 public function generate_paypal_form($order_id)
 {
     $order = new jigoshop_order($order_id);
     if ($this->testmode == 'yes') {
         $url = $this->testurl . '?test_ipn=1&';
     } else {
         $url = $this->liveurl . '?';
     }
     if (in_array($order->billing_country, array('US', 'CA'))) {
         $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone);
         $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
     } else {
         $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
     }
     // filter redirect page
     $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
     $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->testmode == 'yes' ? $this->testemail : $this->email, 'no_note' => 1, 'currency_code' => Jigoshop_Base::get_options()->get('jigoshop_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->get_order_number(), 'amount' => number_format((double) $order->order_total, $this->decimals), 'bn' => 'Jigoshop_SP'), $phone_args);
     if ($this->send_shipping == 'yes') {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 1;
         $paypal_args['first_name'] = $order->shipping_first_name;
         $paypal_args['last_name'] = $order->shipping_last_name;
         $paypal_args['address1'] = $order->shipping_address_1;
         $paypal_args['address2'] = $order->shipping_address_2;
         $paypal_args['city'] = $order->shipping_city;
         $paypal_args['state'] = $order->shipping_state;
         $paypal_args['zip'] = $order->shipping_postcode;
         $paypal_args['country'] = $order->shipping_country;
         // PayPal counts Puerto Rico as a US Territory, won't allow payment without it
         if ($paypal_args['country'] == 'PR') {
             $paypal_args['country'] = 'US';
             $paypal_args['state'] = 'PR';
         }
     } else {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 0;
     }
     // If prices include tax, send the whole order as a single item
     if (Jigoshop_Base::get_options()->get('jigoshop_prices_include_tax') == 'yes') {
         // Discount
         $paypal_args['discount_amount_cart'] = number_format((double) $order->order_discount, $this->decimals);
         // Don't pass items - PayPal breaks tax due to catalog prices include tax.
         // PayPal has no option for tax inclusive pricing.
         // Pass 1 item for the order items overall
         $item_names = array();
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             $title = $_product->get_title();
             //if variation, insert variation details into product title
             if ($_product instanceof jigoshop_product_variation) {
                 $title .= ' (' . jigoshop_get_formatted_variation($_product, $item['variation'], true) . ')';
             }
             $item_names[] = $title . ' x ' . $item['qty'];
         }
         $paypal_args['item_name_1'] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()) . ' - ' . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', '');
         if ($order->order_shipping + $order->order_shipping_tax > 0) {
             $paypal_args['item_name_2'] = __('Shipping cost', 'jigoshop');
             $paypal_args['quantity_2'] = '1';
             $paypal_args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', '');
         }
     } else {
         // Cart Contents
         $item_loop = 0;
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             if ($_product->exists() && $item['qty']) {
                 $item_loop++;
                 $title = $_product->get_title();
                 //if variation, insert variation details into product title
                 if ($_product instanceof jigoshop_product_variation) {
                     $title .= ' (' . jigoshop_get_formatted_variation($_product, $item['variation'], true) . ')';
                 }
                 $paypal_args['item_name_' . $item_loop] = $title;
                 $paypal_args['quantity_' . $item_loop] = $item['qty'];
                 $paypal_args['amount_' . $item_loop] = number_format(apply_filters('jigoshop_paypal_adjust_item_price', $item['cost'], $item, 10, 2), $this->decimals);
                 //Apparently, Paypal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue.
             }
         }
         // Shipping Cost
         if (jigoshop_shipping::is_enabled() && $order->order_shipping > 0) {
             $item_loop++;
             $paypal_args['item_name_' . $item_loop] = __('Shipping cost', 'jigoshop');
             $paypal_args['quantity_' . $item_loop] = '1';
             $paypal_args['amount_' . $item_loop] = number_format((double) $order->order_shipping, $this->decimals);
         }
         $paypal_args['tax'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['tax_cart'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['discount_amount_cart'] = $order->order_discount;
         if ($this->force_payment == 'yes') {
             $sum = 0;
             for ($i = 1; $i < $item_loop; $i++) {
                 $sum += $paypal_args['amount_' . $i];
             }
             $item_loop++;
             if ($sum == 0 || $order->order_discount && $sum - $order->order_discount == 0) {
                 $paypal_args['item_name_' . $item_loop] = __('Force payment on free', 'jigoshop');
                 $paypal_args['quantity_' . $item_loop] = '1';
                 $paypal_args['amount_' . $item_loop] = 0.01;
                 // force payment
             }
         }
     }
     $paypal_args = apply_filters('jigoshop_paypal_args', $paypal_args);
     return jigoshop_render_result('gateways/paypal', array('url' => $url, 'fields' => $paypal_args));
 }
Esempio n. 17
0
/**
 * Order totals meta box
 *
 * Displays the order totals meta box
 *
 * @since 		1.0
 */
function jigoshop_order_totals_meta_box($post)
{
    $_order = new jigoshop_order($post->ID);
    $coupons = array();
    $order_discount_coupons = (array) $_order->_fetch('order_discount_coupons');
    if (!empty($order_discount_coupons)) {
        foreach ($order_discount_coupons as $coupon) {
            $coupons[] = isset($coupon['code']) ? $coupon['code'] : '';
        }
    }
    ?>
	<ul class="totals">
		<li class="left">
			<label><?php 
    _e('Subtotal:', 'jigoshop');
    ?>
</label>
			<input type="text" id="order_subtotal" name="order_subtotal" placeholder="0.00 <?php 
    _e('(ex. tax)', 'jigoshop');
    ?>
" value="<?php 
    echo esc_attr($_order->_fetch('order_subtotal'));
    ?>
" class="first" />
		</li>

		<li class="right">
			<label><?php 
    _e('Discount: ', 'jigoshop');
    ?>
<span class="applied-coupons-values"><?php 
    echo implode(',', $coupons);
    ?>
</span></label>
			<input type="text" id="order_discount" name="order_discount" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_discount'));
    ?>
" />
		</li>
		<?php 
    $shipping_methods = jigoshop_shipping::get_all_methods();
    $shipping_select = "<select id='shipping_method' name='shipping_method' class='last' data-placeholder=" . __('Choose', 'jigoshop') . ">";
    $shipping_select .= "<option></option>";
    if (!empty($shipping_methods)) {
        foreach ($shipping_methods as $index => $method) {
            $mark = '';
            if ($_order->_fetch('shipping_method') == $method->id) {
                $mark = 'selected="selected"';
            }
            $shipping_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>";
        }
    }
    $shipping_select .= "</select>";
    ?>
		<li>
			<label><?php 
    _e('Shipping:', 'jigoshop');
    ?>
</label>
            <input type="text" id="order_shipping" name="order_shipping" placeholder="0.00 <?php 
    _e('(ex. tax)', 'jigoshop');
    ?>
" value="<?php 
    echo esc_attr($_order->_fetch('order_shipping'));
    ?>
" class="first" /> <?php 
    echo $shipping_select;
    ?>
			<script type="text/javascript">
				/*<![CDATA[*/
					jQuery(function() {
						jQuery("#shipping_method").select2({ width: '120px' });
					});
				/*]]>*/
			</script>
        </li>

		<li class="left">
			<label><?php 
    _e('Total Tax:', 'jigoshop');
    ?>
</label>
			<input type="text" id="order_tax" name="order_tax_total" placeholder="0.00" value="<?php 
    echo esc_attr($_order->get_total_tax());
    ?>
" class="first" />
		</li>

		<li class="right">
			<label><?php 
    _e('Shipping Tax:', 'jigoshop');
    ?>
</label>
			<input type="text" id="order_shipping_tax" name="order_shipping_tax" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_shipping_tax'));
    ?>
" class="first" />
		</li>
		<?php 
    $payment_methods = jigoshop_payment_gateways::get_available_payment_gateways();
    $payment_select = "<select id='payment_method' name='payment_method' class='last' data-placeholder=" . __('Choose', 'jigoshop') . ">";
    $payment_select .= "<option></option>";
    if (!empty($payment_methods)) {
        foreach ($payment_methods as $index => $method) {
            $mark = '';
            if ($_order->_fetch('payment_method') == $method->id) {
                $mark = 'selected="selected"';
            }
            $payment_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>";
        }
    }
    $payment_select .= "</select>";
    ?>
		<?php 
    do_action('jigoshop_admin_order_totals_after_shipping', $post->ID);
    ?>
		<li>
			<label><?php 
    _e('Total:', 'jigoshop');
    ?>
</label>
            <input type="text" id="order_total" name="order_total" placeholder="0.00" value="<?php 
    echo esc_attr($_order->_fetch('order_total'));
    ?>
" class="first" /> <?php 
    echo $payment_select;
    ?>
			<script type="text/javascript">
				/*<![CDATA[*/
					jQuery(function() {
						jQuery("#payment_method").select2({ width: '120px' });
					});
				/*]]>*/
			</script>
		</li>

	</ul>
	<div class="clear"></div>
	<?php 
}
 /**
  * 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'));
         }
     }
 }
Esempio n. 19
0
 public static function get_cart_shipping_title()
 {
     // in this instance we want the title of the shipping method only. If no title is provided, use the label.
     $title = jigoshop_shipping::get_chosen_method_title();
     $label = $title ? $title : jigoshop_shipping::get_label();
     if (!$label) {
         return false;
     }
     return sprintf(__('via %s', 'jigoshop'), $label);
 }
Esempio n. 20
0
// Drop-ins (addons, premium features etc)
$include_files = array_merge($include_files, (array) glob( dirname(__FILE__)."/drop-ins/*.php" ));

if ($include_files) :
	foreach($include_files as $filename) :
		if (!empty($filename) && strstr($filename, 'php')) :
			include_once($filename);
		endif;
	endforeach;
endif;
			
$jigoshop 					= jigoshop::get();
		
// Init class singletons
$jigoshop_customer 			= jigoshop_customer::get();				// Customer class, sorts out session data such as location
$jigoshop_shipping 			= jigoshop_shipping::get();				// Shipping class. loads and stores shipping methods
$jigoshop_payment_gateways 	= jigoshop_payment_gateways::get();		// Payment gateways class. loads and stores payment methods
$jigoshop_cart 				= jigoshop_cart::get();					// Cart class, stores the cart contents
		
// Constants
if (!defined('JIGOSHOP_USE_CSS')) :
	if (get_option('jigoshop_disable_css')=='yes') define('JIGOSHOP_USE_CSS', false);
	else define('JIGOSHOP_USE_CSS', true);
endif;
if (!defined('JIGOSHOP_TEMPLATE_URL')) define('JIGOSHOP_TEMPLATE_URL', 'jigoshop/'); // Trailing slash is important :)
		
/**
 * Add post thumbnail support to wordpress
 **/
add_theme_support( 'post-thumbnails' );
	
    function jigoshop_shipping_calculator()
    {
        if (jigoshop_shipping::show_shipping_calculator()) {
            ?>
			<form class="shipping_calculator" action="<?php 
            echo esc_url(jigoshop_cart::get_cart_url());
            ?>
" method="post">
				<h2><a href="#" class="shipping-calculator-button"><?php 
            _e('Calculate Shipping', 'jigoshop');
            ?>
<span>&darr;</span></a></h2>
				<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">
							<?php 
            foreach (jigoshop_countries::get_allowed_countries() as $key => $value) {
                ?>
								<option value="<?php 
                echo esc_attr($key);
                ?>
" <?php 
                selected(jigoshop_customer::get_shipping_country(), $key);
                ?>
><?php 
                echo $value;
                ?>
</option>
							<?php 
            }
            ?>
						</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 (jigoshop_countries::country_has_states($current_cc)) {
                // 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="' . esc_attr($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 esc_attr($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 esc_attr(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>
						<?php 
            do_action('jigoshop_after_shipping_calculator_fields');
            ?>
					</div>
					<p>
						<button type="submit" name="calc_shipping" value="1" class="button"><?php 
            _e('Update Totals', 'jigoshop');
            ?>
</button>
					</p>
					<p>
						<?php 
            $available_methods = jigoshop_shipping::get_available_shipping_methods();
            foreach ($available_methods as $method) {
                for ($i = 0; $i < $method->get_rates_amount(); $i++) {
                    ?>
					<div class="col2-set">
						<p class="form-row col-1">
							<?php 
                    echo '<input type="radio" name="shipping_rates" value="' . esc_attr($method->id . ':' . $i) . '"' . ' class="shipping_select"';
                    if ($method->get_cheapest_service() == $method->get_selected_service($i) && $method->is_chosen()) {
                        echo ' checked>';
                    } else {
                        echo '>';
                    }
                    echo $method->get_selected_service($i);
                    ?>
						<p class="form-row col-2"><?php 
                    if ($method->get_selected_price($i) > 0) {
                        echo jigoshop_price($method->get_selected_price($i));
                        echo __(' (ex. tax)', 'jigoshop');
                    } else {
                        echo __('Free', 'jigoshop');
                    }
                    ?>
					</div>
					<?php 
                }
            }
            ?>
					<input type="hidden" name="cart-url" value="<?php 
            echo esc_attr(jigoshop_cart::get_cart_url());
            ?>
">
					<?php 
            jigoshop::nonce_field('cart');
            ?>
				</section>
			</form>
		<?php 
        }
    }
Esempio n. 22
0
				<th><?php _e('Qty', 'jigoshop'); ?></th>
				<th><?php _e('Totals', 'jigoshop'); ?></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="2"><?php _e('Subtotal', 'jigoshop'); ?></td>
				<td><?php echo jigoshop_cart::get_cart_subtotal(); ?></td>
			</tr>
			
			<?php  if (jigoshop_cart::needs_shipping()) : ?>
				<td colspan="2"><?php _e('Shipping', 'jigoshop'); ?></td>
				<td>
				<?php
				
					$available_methods = jigoshop_shipping::get_available_shipping_methods();
					
					if (sizeof($available_methods)>0) :
						
						echo '<select name="shipping_method" id="shipping_method">';
						
						foreach ($available_methods as $method ) :
							
							echo '<option value="'.$method->id.'" ';
							
							if ($method->chosen) echo 'selected="selected"';
							
							echo '>'.$method->title.' &ndash; ';
							
							if ($method->shipping_total>0) :
								echo jigoshop_price($method->shipping_total);
Esempio n. 23
0
// Payment Gateways
$include_files = array_merge($include_files, (array) glob(dirname(__FILE__) . "/gateways/*.php"));
// Drop-ins (addons, premium features etc)
$include_files = array_merge($include_files, (array) glob(dirname(__FILE__) . "/drop-ins/*.php"));
if ($include_files) {
    foreach ($include_files as $filename) {
        if (!empty($filename) && strstr($filename, 'php')) {
            include_once $filename;
        }
    }
}
$jigoshop = jigoshop::get();
// Init class singletons
$jigoshop_customer = jigoshop_customer::get();
// Customer class, sorts out session data such as location
$jigoshop_shipping = jigoshop_shipping::get();
// Shipping class. loads and stores shipping methods
$jigoshop_payment_gateways = jigoshop_payment_gateways::get();
// Payment gateways class. loads and stores payment methods
$jigoshop_cart = jigoshop_cart::get();
// Cart class, stores the cart contents
// Constants
if (!defined('JIGOSHOP_USE_CSS')) {
    if (get_option('jigoshop_disable_css') == 'yes') {
        define('JIGOSHOP_USE_CSS', false);
    } else {
        define('JIGOSHOP_USE_CSS', true);
    }
}
if (!defined('JIGOSHOP_TEMPLATE_URL')) {
    define('JIGOSHOP_TEMPLATE_URL', 'jigoshop/');