/** get class instance */
	public static function get() {
        if (!isset(self::$_instance)) {
            $c = __CLASS__;
            self::$_instance = new $c;
        }
        return self::$_instance;
    }
 public function is_available()
 {
     if ($this->get_enabled() == "no") {
         return false;
     }
     if (isset(jigoshop_cart::$cart_contents_total_ex_dl) && isset($this->min_amount) && $this->min_amount && apply_filters('jigoshop_shipping_min_amount', $this->min_amount, $this) > jigoshop_cart::$cart_contents_total_ex_dl - jigoshop_cart::$discount_total) {
         return false;
     }
     if (is_array($this->get_ship_to_countries()) && !in_array(jigoshop_customer::get_shipping_country(), $this->get_ship_to_countries())) {
         $this->set_error_message('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.');
         return false;
     }
     return !$this->has_error;
 }
示例#3
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()));
}
    public function is_available() {
    	
    	if ($this->enabled=="no") return false;
    	
		if (isset(jigoshop_cart::$cart_contents_total) && isset($this->min_amount) && $this->min_amount && $this->min_amount > jigoshop_cart::$cart_contents_total) return false;
		
		$ship_to_countries = '';
		
		if ($this->availability == 'specific') :
			$ship_to_countries = $this->countries;
		else :
			if (get_option('jigoshop_allowed_countries')=='specific') :
				$ship_to_countries = get_option('jigoshop_specific_allowed_countries');
			endif;
		endif; 
		
		if (is_array($ship_to_countries)) :
			if (!in_array(jigoshop_customer::get_shipping_country(), $ship_to_countries)) return false;
		endif;
		
		return true;
		
    } 
示例#5
0
function jigoshop_frontend_scripts()
{
    $options = Jigoshop_Base::get_options();
    $frontend_css = JIGOSHOP_URL . '/assets/css/frontend.css';
    $theme_css = file_exists(get_stylesheet_directory() . '/jigoshop/style.css') ? get_stylesheet_directory_uri() . '/jigoshop/style.css' : $frontend_css;
    if ($options->get('jigoshop_disable_css') == 'no') {
        if ($options->get('jigoshop_frontend_with_theme_css') == 'yes' && $frontend_css != $theme_css) {
            jrto_enqueue_style('frontend', 'jigoshop_theme_styles', $frontend_css);
        }
        jrto_enqueue_style('frontend', 'jigoshop_styles', $theme_css);
    }
    wp_enqueue_script('jquery');
    wp_register_script('jquery-blockui', '//cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.min.js', array('jquery'), '2.66.0');
    wp_enqueue_script('jquery-blockui');
    jrto_enqueue_script('frontend', 'jigoshop_global', JIGOSHOP_URL . '/assets/js/global.js', array('jquery'), array('in_footer' => true));
    if ($options->get('jigoshop_disable_fancybox') == 'no') {
        jrto_enqueue_script('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/js/jquery.prettyPhoto.js', array('jquery'), array('in_footer' => true));
        jrto_enqueue_style('frontend', 'prettyPhoto', JIGOSHOP_URL . '/assets/css/prettyPhoto.css');
    }
    jrto_enqueue_script('frontend', 'jigoshop-cart', JIGOSHOP_URL . '/assets/js/cart.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_CART));
    jrto_enqueue_script('frontend', 'jigoshop-checkout', JIGOSHOP_URL . '/assets/js/checkout.js', array('jquery', 'jquery-blockui'), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_PAY)));
    jrto_enqueue_script('frontend', 'jigoshop-validation', JIGOSHOP_URL . '/assets/js/validation.js', array(), array('in_footer' => true, 'page' => JIGOSHOP_CHECKOUT));
    jrto_enqueue_script('frontend', 'jigoshop-payment', JIGOSHOP_URL . '/assets/js/pay.js', array('jquery'), array('page' => JIGOSHOP_PAY));
    jrto_enqueue_script('frontend', 'jigoshop-single-product', JIGOSHOP_URL . '/assets/js/single-product.js', array('jquery'), array('in_footer' => true, 'page' => JIGOSHOP_PRODUCT));
    jrto_enqueue_script('frontend', 'jigoshop-countries', JIGOSHOP_URL . '/assets/js/countries.js', array(), array('in_footer' => true, 'page' => array(JIGOSHOP_CHECKOUT, JIGOSHOP_CART, JIGOSHOP_EDIT_ADDRESS)));
    /* Script.js variables */
    // TODO: clean this up, a lot aren't even used anymore, do away with it
    $jigoshop_params = array('ajax_url' => admin_url('admin-ajax.php', 'jigoshop'), 'assets_url' => JIGOSHOP_URL, 'validate_postcode' => $options->get('jigoshop_enable_postcode_validating', 'no'), 'checkout_url' => admin_url('admin-ajax.php?action=jigoshop-checkout', 'jigoshop'), 'currency_symbol' => get_jigoshop_currency_symbol(), 'get_variation_nonce' => wp_create_nonce("get-variation"), 'load_fancybox' => $options->get('jigoshop_disable_fancybox') == 'no', 'option_guest_checkout' => $options->get('jigoshop_enable_guest_checkout'), 'select_state_text' => __('Select a state…', 'jigoshop'), 'state_text' => __('state', 'jigoshop'), 'ratings_message' => __('Please select a star to rate your review.', 'jigoshop'), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'billing_state' => jigoshop_customer::get_state(), 'shipping_state' => jigoshop_customer::get_shipping_state(), 'is_checkout' => is_page(jigoshop_get_page_id('checkout')) || is_page(jigoshop_get_page_id('pay')), 'error_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_error_disappear_time', 8000), 'message_hide_time' => Jigoshop_Base::get_options()->get('jigoshop_message_disappear_time', 4000));
    if (isset(jigoshop_session::instance()->min_price)) {
        $jigoshop_params['min_price'] = $_GET['min_price'];
    }
    if (isset(jigoshop_session::instance()->max_price)) {
        $jigoshop_params['max_price'] = $_GET['max_price'];
    }
    $jigoshop_params = apply_filters('jigoshop_params', $jigoshop_params);
    jrto_localize_script('jigoshop_global', 'jigoshop_params', $jigoshop_params);
}
	/**
	 * Outputs a form field
	 *
	 * @param   array	args	contains a list of args for showing the field, merged with defaults (below)
	 */
	function checkout_form_field( $args ) {
		
		$defaults = array(
			'type' => 'input',
			'name' => '',
			'label' => '',
			'placeholder' => '',
			'required' => false,
			'class' => array(),
			'label_class' => array(),
			'rel' => '',
			'return' => false
		);
		
		$args = wp_parse_args( $args, $defaults );

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

			break;
			case "state" :
				
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>';
					
				$current_cc = $this->get_value($args['rel']);
				if (!$current_cc) $current_cc = jigoshop_customer::get_country();
				
				$current_r = $this->get_value($args['name']);
				if (!$current_r) $current_r = jigoshop_customer::get_state();
				
				$states = jigoshop_countries::$states;	
					
				if (isset( $states[$current_cc][$current_r] )) :
					// Dropdown
					$field .= '<select name="'.$args['name'].'" id="'.$args['name'].'"><option value="">'.__('Select a state&hellip;', 'jigoshop').'</option>';
					foreach($states[$current_cc] as $key=>$value) :
						$field .= '<option value="'.$key.'"';
						if ($current_r==$key) $field .= 'selected="selected"';
						$field .= '>'.__($value, 'jigoshop').'</option>';
					endforeach;
					$field .= '</select>';
				else :
					// Input
					$field .= '<input type="text" class="input-text" value="'.$current_r.'" placeholder="'.__('State/County', 'jigoshop').'" name="'.$args['name'].'" id="'.$args['name'].'" />';
				endif;
	
				$field .= '</p>'.$after;
				
			break;
			case "textarea" :
				
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>
					<textarea name="'.$args['name'].'" class="input-text" id="'.$args['name'].'" placeholder="'.$args['placeholder'].'" cols="5" rows="2">'. $this->get_value( $args['name'] ).'</textarea>
				</p>'.$after;
				
			break;
			default :
			
				$field = '<p class="form-row '.implode(' ', $args['class']).'">
					<label for="'.$args['name'].'" class="'.implode(' ', $args['label_class']).'">'.$args['label'].$required.'</label>
					<input type="'.$args['type'].'" class="input-text" name="'.$args['name'].'" id="'.$args['name'].'" placeholder="'.$args['placeholder'].'" value="'. $this->get_value( $args['name'] ).'" />
				</p>'.$after;
				
			break;
		endswitch;
		
		if ($args['return']) return $field; else echo $field;
	}
示例#7
0
						<li>
						<input type="radio" id="payment_method_<?php echo $gateway->id; ?>" class="input-radio" name="payment_method" value="<?php echo $gateway->id; ?>" <?php if ($gateway->chosen) echo 'checked="checked"'; ?> />
						<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->title; ?> <?php echo apply_filters('gateway_icon', $gateway->icon(), $gateway->id); ?></label> 
							<?php
								if ($gateway->has_fields || $gateway->description) : 
									echo '<div class="payment_box payment_method_'.$gateway->id.'" style="display:none;">';
									$gateway->payment_fields();
									echo '</div>';
								endif;
							?>
						</li>
						<?php
					endforeach;
				else :
				
					if ( !jigoshop_customer::get_country() ) :
						echo '<p>'.__('Please fill in your details above to see available payment methods.', 'jigoshop').'</p>';
					else :
						echo '<p>'.__('Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'jigoshop').'</p>';
					endif;
					
				endif;
			?>
		</ul>
		<?php endif; ?>

		<div class="form-row">
		
			<noscript><?php _e('Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'jigoshop'); ?><br/><input type="submit" class="button-alt" name="update_totals" value="<?php _e('Update totals', 'jigoshop'); ?>" /></noscript>
		
			<?php jigoshop::nonce_field('process_checkout')?>
示例#8
0
文件: pay.php 项目: ashik968/digiplot
function jigoshop_pay_action()
{
    if (!is_jigoshop_single_page(JIGOSHOP_PAY)) {
        return;
    }
    if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) {
        // Pay for existing order
        $order_key = urldecode($_GET['order']);
        $order_id = (int) $_GET['order_id'];
        $order = new jigoshop_order($order_id);
        if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending') {
            // Set customer location to order location
            if ($order->billing_country) {
                jigoshop_customer::set_country($order->billing_country);
            }
            if ($order->billing_state) {
                jigoshop_customer::set_state($order->billing_state);
            }
            if ($order->billing_postcode) {
                jigoshop_customer::set_postcode($order->billing_postcode);
            }
            // Pay form was posted - process payment
            if (isset($_POST['pay']) && jigoshop::verify_nonce('pay')) {
                // Update payment method
                if ($order->order_total > 0) {
                    $payment_method = jigowatt_clean($_POST['payment_method']);
                    $data = (array) maybe_unserialize(get_post_meta($order_id, 'order_data', true));
                    $data['payment_method'] = $payment_method;
                    update_post_meta($order_id, 'order_data', $data);
                    $available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
                    $result = $available_gateways[$payment_method]->process_payment($order_id);
                    // Redirect to success/confirmation/payment page
                    if ($result['result'] == 'success') {
                        wp_safe_redirect($result['redirect']);
                        exit;
                    }
                } else {
                    // No payment was required for order
                    $order->payment_complete();
                    // filter redirect page
                    $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks'));
                    wp_safe_redirect(get_permalink($checkout_redirect));
                    exit;
                }
            }
        } elseif ($order->status != 'pending') {
            jigoshop::add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'jigoshop'));
        } else {
            jigoshop::add_error(__('Invalid order.', 'jigoshop'));
        }
    } else {
        // Pay for order after checkout step
        if (isset($_GET['order'])) {
            $order_id = $_GET['order'];
        } else {
            $order_id = 0;
        }
        if (isset($_GET['key'])) {
            $order_key = $_GET['key'];
        } else {
            $order_key = '';
        }
        if ($order_id > 0) {
            $order = new jigoshop_order($order_id);
            if ($order->order_key != $order_key || $order->status != 'pending') {
                wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
                exit;
            }
        } else {
            wp_safe_redirect(apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))));
            exit;
        }
    }
}
示例#9
0
/**
 * Outputs the pay page - payment gateways can hook in here to show payment forms etc
 **/
function jigoshop_pay() {
	
	if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
		
		// Pay for existing order
		$order_key = urldecode( $_GET['order'] );
		$order_id = (int) $_GET['order_id'];
		$order = &new jigoshop_order( $order_id );
		
		if ($order->id == $order_id && $order->order_key == $order_key && $order->status=='pending') :
			
			// Set customer location to order location
			if ($order->billing_country) jigoshop_customer::set_country( $order->billing_country );
			if ($order->billing_state) jigoshop_customer::set_state( $order->billing_state );
			if ($order->billing_postcode) jigoshop_customer::set_postcode( $order->billing_postcode );
			
			// Pay form was posted - process payment
			if (isset($_POST['pay']) && jigoshop::verify_nonce('pay')) :
			
				// Update payment method
				if ($order->order_total > 0 ) : 
					$payment_method 			= jigowatt_clean($_POST['payment_method']);
					$data 						= (array) maybe_unserialize( get_post_meta( $order_id, 'order_data', true ) );
					$data['payment_method']		= $payment_method;
					update_post_meta( $order_id, 'order_data', $data );
			
					$available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
				
					$result = $available_gateways[$payment_method]->process_payment( $order_id );
					
					// Redirect to success/confirmation/payment page
					if ($result['result']=='success') :
						wp_safe_redirect( $result['redirect'] );
						exit;
					endif;
				else :
					
					// No payment was required for order
					$order->payment_complete();
					wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) );
					exit;
					
				endif;
	
			endif;
			
			// Show messages
			jigoshop::show_messages();
			
			// Show form
			jigoshop_pay_for_existing_order( $order );
		
		elseif ($order->status!='pending') :
			
			jigoshop::add_error( __('Your order has already been paid for. Please contact us if you need assistance.', 'jigoshop') );
			
			jigoshop::show_messages();
			
		else :
		
			jigoshop::add_error( __('Invalid order.', 'jigoshop') );
			
			jigoshop::show_messages();
			
		endif;
		
	else :
		
		// Pay for order after checkout step
		if (isset($_GET['order'])) $order_id = $_GET['order']; else $order_id = 0;
		if (isset($_GET['key'])) $order_key = $_GET['key']; else $order_key = '';
		
		if ($order_id > 0) :
		
			$order = &new jigoshop_order( $order_id );
		
			if ($order->order_key == $order_key && $order->status=='pending') :
		
				?>
				<ul class="order_details">
					<li class="order">
						<?php _e('Order:', 'jigoshop'); ?>
						<strong># <?php echo $order->id; ?></strong>
					</li>
					<li class="date">
						<?php _e('Date:', 'jigoshop'); ?>
						<strong><?php echo date(get_option('date_format'), strtotime($order->order_date)); ?></strong>
					</li>
					<li class="total">
						<?php _e('Total:', 'jigoshop'); ?>
						<strong><?php echo jigoshop_price($order->order_total); ?></strong>
					</li>
					<li class="method">
						<?php _e('Payment method:', 'jigoshop'); ?>
						<strong><?php 
							$gateways = jigoshop_payment_gateways::payment_gateways();
							if (isset($gateways[$order->payment_method])) echo $gateways[$order->payment_method]->title;
							else echo $order->payment_method; 
						?></strong>
					</li>
				</ul>
				
				<?php do_action( 'receipt_' . $order->payment_method, $order_id ); ?>
				
				<div class="clear"></div>
				<?php
				
			else :
			
				wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
				exit;
				
			endif;
			
		else :
			
			wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
			exit;
			
		endif;

	endif;
}
示例#10
0
	/**
	 * Get the tax rate based on the country and state
	 *
	 * @param   object	Tax Class
	 * @return  mixed		
	 */
	function get_shipping_tax_rate( $tax_class = '' ) {
		
		if (defined('JIGOSHOP_CHECKOUT') && JIGOSHOP_CHECKOUT) :
			$country 	= jigoshop_customer::get_country();
			$state 		= jigoshop_customer::get_state();
		else :
			$country 	= jigoshop_countries::get_base_country();
			$state 		= jigoshop_countries::get_base_state();
		endif;
		
		// If we are here then shipping is taxable - work it out
		
		if ($tax_class) :
			
			// This will be per item shipping
			$rate = $this->find_rate( $country, $state, $tax_class );
			
			if (isset($rate['shipping']) && $rate['shipping']=='yes') :
				return $rate['rate'];
			else :
				// Get standard rate
				$rate = $this->find_rate( $country, $state );
				if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
			endif;
			
		else :
			
			// This will be per order shipping - loop through the order and find the highest tax class rate
			
			$found_rates = array();
			$found_shipping_rates = array();
			
			// Loop cart and find the highest tax band
			if (sizeof(jigoshop_cart::$cart_contents)>0) : foreach (jigoshop_cart::$cart_contents as $item) :
				
				if ($item['data']->data['tax_class']) :
					
					$found_rate = $this->find_rate( $country, $state, $item['data']->data['tax_class'] );
					
					$found_rates[] = $found_rate['rate'];
					
					if (isset($found_rate['shipping']) && $found_rate['shipping']=='yes') $found_shipping_rates[] = $found_rate['rate'];
					
				endif;
				
			endforeach; endif;
			
			if (sizeof($found_rates) > 0 && sizeof($found_shipping_rates) > 0) :
				
				rsort($found_rates);
				rsort($found_shipping_rates);
				
				if ($found_rates[0] == $found_shipping_rates[0]) :
					return $found_shipping_rates[0];
				else :
					// Use standard rate
					$rate = $this->find_rate( $country, $state );
					if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
				endif;
				
			else :
				// Use standard rate
				$rate = $this->find_rate( $country, $state );	
				if (isset($rate['shipping']) && $rate['shipping']=='yes') return $rate['rate'];
			endif;
			
		endif;

		return 0; // return false
	}
	function estimated_for_prefix() {
		$return = '';
		if (in_array(jigoshop_customer::get_country(), array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ))) $return = __('the ', 'jigoshop');
		$return = apply_filters('estimated_for_prefix', $return, jigoshop_customer::get_shipping_country());
		return $return;
	}
示例#12
0
function jigoshop_cart( $atts ) {
	
	$errors = array();
	
	// Process Discount Codes
	if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && jigoshop::verify_nonce('cart')) :
	
		$coupon_code = stripslashes(trim($_POST['coupon_code']));
		jigoshop_cart::add_discount($coupon_code);

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

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

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

			<?php
			else :
				echo '<p>'.__('Sorry, it seems that there are no available shipping methods to your location. Please contact us if you require assistance or wish to make alternate arrangements.', 'jigoshop').'</p>';
			endif;
		?>
		</div>
		
		<?php jigoshop_shipping_calculator(); ?>
		
	</div>
	<?php		
}
示例#13
0
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 
}
示例#14
0
/**
 * @var $available_methods array List of available shipping methods.
 */
?>

<?php 
$available_methods = jigoshop_shipping::get_available_shipping_methods();
?>
<tr>
	<td colspan="2"><?php 
_e('Shipping', 'jigoshop');
?>
<br />
		<small><?php 
echo _x('To: ', 'shipping destination', 'jigoshop') . __(jigoshop_customer::get_shipping_country_or_state(), 'jigoshop');
?>
</small>
	</td>
	<td>
		<?php 
if (count($available_methods) > 0) {
    ?>
		<select name="shipping_method" id="shipping_method">
			<?php 
    foreach ($available_methods as $method) {
        /** @var jigoshop_shipping_method $method */
        ?>
				<?php 
        for ($i = 0; $i < $method->get_rates_amount(); $i++) {
            $service = $method->get_selected_service($i);
示例#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;
	}
示例#16
0
 * @var $recent_orders int Number of recent orders to show.
 */
jigoshop::show_messages();
if (is_user_logged_in()) {
    ?>
<p><?php 
    echo sprintf(__('Hello, <strong>%s</strong>. From your account dashboard you can view your recent orders, manage your shipping and billing addresses and <a href="%s">change your password</a>.', 'jigoshop'), $current_user->display_name, apply_filters('jigoshop_get_change_password_page_id', get_permalink(jigoshop_get_page_id('change_password'))));
    ?>
</p>

<?php 
    do_action('jigoshop_before_my_account');
    ?>

<?php 
    if ($downloads = jigoshop_customer::get_downloadable_products()) {
        ?>
	<h2><?php 
        _e('Available downloads', 'jigoshop');
        ?>
</h2>
	<ul class="digital-downloads">
		<?php 
        foreach ($downloads as $download) {
            ?>
			<li><?php 
            if (is_numeric($download['downloads_remaining'])) {
                ?>
<span class="count"><?php 
                echo $download['downloads_remaining'] . _n(' download Remaining', ' downloads Remaining', 'jigoshop');
                ?>
示例#17
0
function jigoshop_edit_address() {
	
	$user_id = get_current_user_id();
	
	if (is_user_logged_in()) :
		
		if (isset($_GET['address'])) $load_address = $_GET['address']; else $load_address = 'billing';
		if ($load_address == 'billing') $load_address = 'billing'; else $load_address = 'shipping';
		
		if ($_POST) :
		
			if ($user_id>0 && jigoshop::verify_nonce('edit_address') ) :
				update_user_meta( $user_id, $load_address . '-first_name', jigowatt_clean($_POST['address-first_name']) );
				update_user_meta( $user_id, $load_address . '-last_name', jigowatt_clean($_POST['address-last_name']) );
				update_user_meta( $user_id, $load_address . '-company', jigowatt_clean($_POST['address-company']) );
				update_user_meta( $user_id, $load_address . '-email', jigowatt_clean($_POST['address-email']) );
				update_user_meta( $user_id, $load_address . '-address', jigowatt_clean($_POST['address-address']) );
				update_user_meta( $user_id, $load_address . '-address2', jigowatt_clean($_POST['address-address2']) );
				update_user_meta( $user_id, $load_address . '-city', jigowatt_clean($_POST['address-city']) );
				update_user_meta( $user_id, $load_address . '-postcode', jigowatt_clean($_POST['address-postcode']) );
				update_user_meta( $user_id, $load_address . '-country', jigowatt_clean($_POST['address-country']) );
				update_user_meta( $user_id, $load_address . '-state', jigowatt_clean($_POST['address-state']) );
				update_user_meta( $user_id, $load_address . '-phone', jigowatt_clean($_POST['address-phone']) );
				update_user_meta( $user_id, $load_address . '-fax', jigowatt_clean($_POST['address-fax']) );
			endif;
			
			wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
			exit;
		
		endif;
		
		$address = array(
			'first_name' => get_user_meta( get_current_user_id(), $load_address . '-first_name', true ),
			'last_name' => get_user_meta( get_current_user_id(), $load_address . '-last_name', true ),
			'company' => get_user_meta( get_current_user_id(), $load_address . '-company', true ),
			'email' => get_user_meta( get_current_user_id(), $load_address . '-email', true ),
			'phone' => get_user_meta( get_current_user_id(), $load_address . '-phone', true ),
			'fax' => get_user_meta( get_current_user_id(), $load_address . '-fax', true ),
			'address' => get_user_meta( get_current_user_id(), $load_address . '-address', true ),
			'address2' => get_user_meta( get_current_user_id(), $load_address . '-address2', true ),
			'city' => get_user_meta( get_current_user_id(), $load_address . '-city', true ),		
			'state' => get_user_meta( get_current_user_id(), $load_address . '-state', true ),
			'postcode' => get_user_meta( get_current_user_id(), $load_address . '-postcode', true ),
			'country' => get_user_meta( get_current_user_id(), $load_address . '-country', true )
		);
		?>
		<form action="<?php echo add_query_arg('address', $load_address, get_permalink(get_option('jigoshop_edit_address_page_id'))); ?>" method="post">
	
			<h3><?php if ($load_address=='billing') _e('Billing Address', 'jigoshop'); else _e('Shipping Address', 'jigoshop'); ?></h3>
			
			<p class="form-row form-row-first">
				<label for="address-first_name"><?php _e('First Name', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-first_name" id="address-first_name" placeholder="<?php _e('First Name', 'jigoshop'); ?>" value="<?php echo $address['first_name']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-last_name"><?php _e('Last Name', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-last_name" id="address-last_name" placeholder="<?php _e('Last Name', 'jigoshop'); ?>" value="<?php echo $address['last_name']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row columned">
				<label for="address-company"><?php _e('Company', 'jigoshop'); ?></label>
				<input type="text" class="input-text" name="address-company" id="address-company" placeholder="<?php _e('Company', 'jigoshop'); ?>" value="<?php echo $address['company']; ?>" />
			</p>
			
			<p class="form-row form-row-first">
				<label for="address-address"><?php _e('Address', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-address" id="address-address" placeholder="<?php _e('1 Infinite Loop', 'jigoshop'); ?>" value="<?php echo $address['address']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-address2" class="hidden"><?php _e('Address 2', 'jigoshop'); ?></label>
				<input type="text" class="input-text" name="address-address2" id="address-address2" placeholder="<?php _e('Cupertino', 'jigoshop'); ?>" value="<?php echo $address['address2']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row form-row-first">
				<label for="address-city"><?php _e('City', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-city" id="address-city" placeholder="<?php _e('City', 'jigoshop'); ?>" value="<?php echo $address['city']; ?>" />
			</p>
			<p class="form-row form-row-last">
				<label for="address-postcode"><?php _e('Postcode', 'jigoshop'); ?> <span class="required">*</span></label>
				<input type="text" class="input-text" name="address-postcode" id="address-postcode" placeholder="123456" value="<?php echo $address['postcode']; ?>" />
			</p>
			<div class="clear"></div>
			
			<p class="form-row form-row-first">
				<label for="address-country"><?php _e('Country', 'jigoshop'); ?> <span class="required">*</span></label>
				<select name="address-country" id="address-country" class="country_to_state" rel="address-state">
					<option value=""><?php _e('Select a country&hellip;', 'jigoshop'); ?></option>
					<?php						
						foreach(jigoshop_countries::$countries as $key=>$value) :
							echo '<option value="'.$key.'"';
							if ($address['country']==$key) echo 'selected="selected"';
							elseif (!$address['country'] && jigoshop_customer::get_country()==$key) echo 'selected="selected"';
							echo '>'.$value.'</option>';
						endforeach;
					?>
				</select>
			</p>
			<p class="form-row form-row-last">	
				<label for="address-state"><?php _e('state', 'jigoshop'); ?> <span class="required">*</span></label>
				<?php 
					$current_cc = $address['country'];
					if (!$current_cc) $current_cc = jigoshop_customer::get_country();
					
					$current_r = $address['state'];
					if (!$current_r) $current_r = jigoshop_customer::get_state();
					
					$states = jigoshop_countries::$states;
					
					if (isset( $states[$current_cc][$current_r] )) :
						// Dropdown
						?>
						<select name="address-state" id="address-state"><option value=""><?php _e('Select a state&hellip;', 'jigoshop'); ?></option><?php
								foreach($states[$current_cc] as $key=>$value) :
									echo '<option value="'.$key.'"';
									if ($current_r==$key) echo 'selected="selected"';
									echo '>'.$value.'</option>';
								endforeach;
						?></select>
						<?php
					else :
						// Input
						?><input type="text" class="input-text" value="<?php echo $current_r; ?>" placeholder="<?php _e('state', 'jigoshop'); ?>" name="address-state" id="address-state" /><?php
					endif;
				?>
			</p>
			<div class="clear"></div>
			
			<?php if ($load_address=='billing') : ?>
				<p class="form-row columned">
					<label for="address-email"><?php _e('Email Address', 'jigoshop'); ?> <span class="required">*</span></label>
					<input type="text" class="input-text" name="address-email" id="address-email" placeholder="<?php _e('*****@*****.**', 'jigoshop'); ?>" value="<?php echo $address['email']; ?>" />
				</p>
				
				<p class="form-row form-row-first">
					<label for="address-phone"><?php _e('Phone', 'jigoshop'); ?> <span class="required">*</span></label>
					<input type="text" class="input-text" name="address-phone" id="address-phone" placeholder="0123456789" value="<?php echo $address['phone']; ?>" />
				</p>
				<p class="form-row form-row-last">	
					<label for="address-fax"><?php _e('Fax', 'jigoshop'); ?></label>
					<input type="text" class="input-text" name="address-fax" id="address-fax" placeholder="0123456789" value="<?php echo $address['fax']; ?>" />
				</p>
				<div class="clear"></div>
			<?php endif; ?>
			<?php jigoshop::nonce_field('edit_address') ?>
			<input type="submit" class="button" name="save_address" value="<?php _e('Save Address', 'jigoshop'); ?>" />
	
		</form>
		<?php
		
	else :
	
		wp_safe_redirect( get_permalink(get_option('jigoshop_myaccount_page_id')) );
		exit;
		
	endif;
}
示例#18
0
 /**
  * Get the tax rate based on the country and state.
  *
  * @param   string $tax_class is the tax class that has shipping tax applied
  * @return  mixed
  * @deprecated - use calculate_shipping_tax($price, $tax_classes) to calculate shipping taxes. No need to get the rates first
  */
 function get_shipping_tax_rate($tax_class = '')
 {
     $this->shipping_tax_class = '';
     $country = jigoshop_customer::get_shipping_country();
     $state = jigoshop_customer::get_shipping_state();
     // If we are here then shipping is taxable - work it out
     if ($tax_class) {
         // This will be per item shipping
         $rate = $this->find_rate($country, $state, $tax_class);
         if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
             $this->shipping_tax_class = $tax_class;
             return $rate['rate'];
         } else {
             // Get standard rate
             $rate = $this->find_rate($country, $state);
             if (isset($rate['shipping']) && $rate['shipping'] == 'yes') {
                 $this->shipping_tax_class = '*';
                 //standard rate
                 return $rate['rate'];
             }
         }
     } else {
         // This will be per order shipping - loop through the order and find the highest tax class rate
         $found_shipping_rates = array();
         $customer_tax_classes = $this->get_tax_classes_for_customer();
         foreach ($customer_tax_classes as $tax_class) {
             $found_rate = $this->find_rate($country, $state, $tax_class);
             if (isset($found_rate['shipping']) && $found_rate['shipping'] == 'yes') {
                 $this->shipping_tax_class = $tax_class;
                 $found_shipping_rates[] = $found_rate['rate'];
             }
         }
         if (sizeof($found_shipping_rates) > 0) {
             rsort($found_shipping_rates);
             return $found_shipping_rates[0];
         }
     }
     return 0;
     // return false
 }
示例#19
0
 public static function get_cart_shipping_total($for_display = true, $order_exclude_tax = false)
 {
     /* Quit early if there is no shipping label. */
     if (!jigoshop_shipping::get_label()) {
         return false;
     }
     // Do not display taxes if shipping country is not set
     if (jigoshop_customer::get_shipping_country() == '') {
         return false;
     }
     /* Shipping price is 0.00. */
     if (jigoshop_shipping::get_total() <= 0) {
         return $for_display ? __('Free!', 'jigoshop') : 0;
     }
     /* Not calculating taxes. */
     if (self::get_options()->get('jigoshop_calc_taxes') == 'no') {
         return $for_display ? jigoshop_price(self::$shipping_total) : number_format(self::$shipping_total, 2, '.', '');
     }
     if (self::get_options()->get('jigoshop_prices_include_tax') == 'no' || $order_exclude_tax) {
         $return = $for_display ? jigoshop_price(self::$shipping_total) : number_format(self::$shipping_total, 2, '.', '');
         if (self::$shipping_tax_total > 0 && $for_display) {
             $return .= ' <small>' . __('(ex. tax)', 'jigoshop') . '</small>';
         }
     } else {
         $return = $for_display ? jigoshop_price(self::$shipping_total + self::$shipping_tax_total) : number_format(self::$shipping_total + self::$shipping_tax_total, 2, '.', '');
         if (self::$shipping_tax_total > 0 && $for_display) {
             $return .= ' <small>' . __('(inc. tax)', 'jigoshop') . '</small>';
         }
     }
     return $return;
 }
 /**
  * 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'));
         }
     }
 }
 function jigoshop_eu_b2b_vat_message()
 {
     if (jigoshop_countries::is_eu_country(jigoshop_customer::get_country()) && Jigoshop_Base::get_options()->get('jigoshop_eu_vat_reduction_message') == 'yes') {
         echo '<div class="clear"></div><div class="payment_message">' . __('If you have entered an EU VAT Number, it will be looked up when you <strong>Place</strong> your Order and verified.  At that time <strong><em>Only</em></strong>, will VAT then be removed from the final Order and totals adjusted.  You may enter your EU VAT Number either with, or without, the 2 character EU country code in front.', 'jigoshop') . '</div>';
     }
 }
    /**
     * Outputs a form field
     *
     * @param array $args contains a list of args for showing the field, merged with defaults (below)
     * @return string
     */
    public static function address_form_field($args)
    {
        $defaults = array('type' => 'text', 'name' => '', 'label' => '', 'placeholder' => '', 'required' => false, 'class' => array(), 'label_class' => array(), 'rel' => '', 'return' => false, 'options' => array(), 'value' => '');
        $args = wp_parse_args($args, $defaults);
        if ($args['required']) {
            $required = ' <span class="required">*</span>';
            $input_required = ' input-required';
        } else {
            $required = '';
            $input_required = '';
        }
        if (in_array('form-row-last', $args['class'])) {
            $after = '<div class="clear"></div>';
        } else {
            $after = '';
        }
        switch ($args['type']) {
            case "country":
                $current_c = self::get_value($args['name']);
                $is_shipping_c = strpos($args['name'], 'shipping');
                if (!$current_c) {
                    if ($is_shipping_c === false) {
                        $current_c = jigoshop_customer::get_country();
                    } else {
                        $current_c = jigoshop_customer::get_shipping_country();
                    }
                }
                // Remove 'Select a Country' option from drop-down menu for countries.
                // There is no need to have it, because was assume when user hasn't selected
                // a country that they are from the shop base country.
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
        <label for="' . esc_attr($args['name']) . '" class="' . esc_attr(implode(' ', $args['label_class'])) . '">' . $args['label'] . $required . '</label>
        <select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="country_to_state" rel="' . esc_attr($args['rel']) . '">';
                foreach (jigoshop_countries::get_allowed_countries() as $key => $value) {
                    $field .= '<option value="' . esc_attr($key) . '"';
                    if (self::get_value($args['name']) == $key) {
                        $field .= ' selected="selected"';
                    } elseif (self::get_value($args['name']) && $current_c == $key) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($value, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            case "state":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>';
                $is_shipping_s = strpos($args['name'], 'shipping');
                $current_cc = self::get_value($args['rel']);
                if (!$current_cc) {
                    if ($is_shipping_s === false) {
                        $current_cc = jigoshop_customer::get_country();
                    } else {
                        $current_cc = jigoshop_customer::get_shipping_country();
                    }
                }
                $current_r = self::get_value($args['name']);
                if (!$current_r) {
                    if ($is_shipping_s === false) {
                        $current_r = jigoshop_customer::get_state();
                    } else {
                        $current_r = jigoshop_customer::get_shipping_state();
                    }
                }
                $states = jigoshop_countries::get_states($current_cc);
                if (!empty($states)) {
                    // Dropdown
                    $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '"><option value="">' . __('Select a state&hellip;', 'jigoshop') . '</option>';
                    foreach ($states as $key => $value) {
                        $field .= '<option value="' . esc_attr($key) . '"';
                        if ($current_r == $key) {
                            $field .= ' selected="selected"';
                        }
                        $field .= '>' . __($value, 'jigoshop') . '</option>';
                    }
                    $field .= '</select>';
                } else {
                    // Input
                    $field .= '<input type="text" class="input-text" value="' . esc_attr($current_r) . '" placeholder="' . __('State/Province', 'jigoshop') . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" />';
                }
                $field .= '</p>' . $after;
                break;
            case "postcode":
                $current_pc = self::get_value($args['name']);
                $is_shipping_pc = strpos($args['name'], 'shipping');
                if (!$current_pc) {
                    if ($is_shipping_pc === false) {
                        $current_pc = jigoshop_customer::get_postcode();
                    } else {
                        $current_pc = jigoshop_customer::get_shipping_postcode();
                    }
                }
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="text" class="input-text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . esc_attr($current_pc) . '" />
				</p>' . $after;
                break;
            case "textarea":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<textarea name="' . esc_attr($args['name']) . '" class="input-text' . esc_attr($input_required) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" cols="5" rows="2">' . esc_textarea(self::get_value($args['name'])) . '</textarea>
				</p>' . $after;
                break;
                //Adds a drop down custom type
            //Adds a drop down custom type
            case "select":
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
						  <label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>';
                $field .= '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($input_required) . '">';
                foreach ($args['options'] as $value => $label) {
                    $field .= '<option value="' . esc_attr($value) . '"';
                    if (self::get_value($args['name']) == $value) {
                        $field .= ' selected="selected"';
                    }
                    $field .= '>' . __($label, 'jigoshop') . '</option>';
                }
                $field .= '</select></p>' . $after;
                break;
            default:
                $field = '<p class="form-row ' . implode(' ', $args['class']) . '">
					<label for="' . esc_attr($args['name']) . '" class="' . implode(' ', $args['label_class']) . '">' . $args['label'] . $required . '</label>
					<input type="' . $args['type'] . '" class="input-text' . esc_attr($input_required) . '" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" placeholder="' . $args['placeholder'] . '" value="' . self::get_value($args['name']) . '" />
				</p>' . $after;
                break;
        }
        $field = apply_filters('jigoshop_address_field_types', $field, $args);
        if ($args['return']) {
            return $field;
        } else {
            echo $field;
            return null;
        }
    }
示例#23
0
function jigoshop_ajax_update_order_review()
{
    check_ajax_referer('update-order-review', 'security');
    if (!defined('JIGOSHOP_CHECKOUT')) {
        define('JIGOSHOP_CHECKOUT', true);
    }
    jigoshop_cart::get_cart();
    if (sizeof(jigoshop_cart::$cart_contents) == 0) {
        echo '<p class="error">' . __('Sorry, your session has expired.', 'jigoshop') . ' <a href="' . home_url() . '">' . __('Return to homepage &rarr;', 'jigoshop') . '</a></p>';
        exit;
    }
    do_action('jigoshop_checkout_update_order_review', $_POST['post_data']);
    if (isset($_POST['shipping_method'])) {
        $shipping_method = explode(":", $_POST['shipping_method']);
        jigoshop_session::instance()->chosen_shipping_method_id = $shipping_method[0];
        if (is_numeric($shipping_method[2])) {
            jigoshop_session::instance()->selected_rate_id = $shipping_method[2];
        }
    }
    if (!empty($_POST['coupon_code'])) {
        jigoshop_cart::add_discount(sanitize_title($_POST['coupon_code']));
        jigoshop::show_messages();
    }
    if (isset($_POST['country'])) {
        jigoshop_customer::set_country($_POST['country']);
    }
    if (isset($_POST['state'])) {
        jigoshop_customer::set_state($_POST['state']);
    }
    if (isset($_POST['postcode'])) {
        jigoshop_customer::set_postcode($_POST['postcode']);
    }
    if (isset($_POST['s_country'])) {
        jigoshop_customer::set_shipping_country($_POST['s_country']);
    }
    if (isset($_POST['s_state'])) {
        jigoshop_customer::set_shipping_state($_POST['s_state']);
    }
    if (isset($_POST['s_postcode'])) {
        jigoshop_customer::set_shipping_postcode($_POST['s_postcode']);
    }
    jigoshop_cart::calculate_totals();
    do_action('jigoshop_checkout_order_review');
    die;
}
示例#24
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' );
示例#25
0
    ?>
		<?php 
} else {
    ?>
			<?php 
    _e('Shipping Address', 'jigoshop');
    ?>
		<?php 
}
?>
	</h3>
	<?php 
foreach ($address as $field) {
    ?>
		<?php 
    jigoshop_customer::address_form_field($field);
    ?>
	<?php 
}
?>
	<?php 
jigoshop::nonce_field('edit_address');
?>
	<input type="submit" class="button" name="save_address" value="<?php 
_e('Save Address', 'jigoshop');
?>
" />
	<a class="button-alt" href="<?php 
echo $account_url;
?>
"><?php 
示例#26
0
    function jigoshop_shipping_calculator()
    {
        if (jigoshop_cart::needs_shipping()) {
            ?>
		<form class="shipping_calculator" action="<?php 
            echo jigoshop_cart::get_cart_url();
            ?>
" method="post">
			<h4><a href="#" class="shipping-calculator-button"><?php 
            _e('Calculate Shipping', 'jigoshop');
            ?>
 <span>&darr;</span></a></h4>
			<section class="shipping-calculator-form">
			<p class="form-row">
				<select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state">
					<option value=""><?php 
            _e('Select a country&hellip;', 'jigoshop');
            ?>
</option>
					<?php 
            foreach (jigoshop_countries::get_allowed_countries() as $key => $value) {
                echo '<option value="' . $key . '"';
                if (jigoshop_customer::get_shipping_country() == $key) {
                    echo 'selected="selected"';
                }
                echo '>' . $value . '</option>';
            }
            ?>
				</select>
			</p>
			<div class="col2-set">
				<p class="form-row col-1">
					<?php 
            $current_cc = jigoshop_customer::get_shipping_country();
            $current_r = jigoshop_customer::get_shipping_state();
            $states = jigoshop_countries::$states;
            if (isset($states[$current_cc][$current_r])) {
                // Dropdown
                ?>
							<span>
								<select name="calc_shipping_state" id="calc_shipping_state"><option value=""><?php 
                _e('Select a state&hellip;', 'jigoshop');
                ?>
</option><?php 
                foreach ($states[$current_cc] as $key => $value) {
                    echo '<option value="' . $key . '"';
                    if ($current_r == $key) {
                        echo 'selected="selected"';
                    }
                    echo '>' . $value . '</option>';
                }
                ?>
</select>
							</span>
							<?php 
            } else {
                // Input
                ?>
							<input type="text" class="input-text" value="<?php 
                echo $current_r;
                ?>
" placeholder="<?php 
                _e('state', 'jigoshop');
                ?>
" name="calc_shipping_state" id="calc_shipping_state" />
							<?php 
            }
            ?>
				</p>
				<p class="form-row col-2">
					<input type="text" class="input-text" value="<?php 
            echo jigoshop_customer::get_shipping_postcode();
            ?>
" placeholder="<?php 
            _e('Postcode/Zip', 'jigoshop');
            ?>
" title="<?php 
            _e('Postcode', 'jigoshop');
            ?>
" name="calc_shipping_postcode" id="calc_shipping_postcode" />
				</p>
			</div>
			<p><button type="submit" name="calc_shipping" value="1" class="button"><?php 
            _e('Update Totals', 'jigoshop');
            ?>
</button></p>
			<?php 
            jigoshop::nonce_field('cart');
            ?>
			</section>
		</form>
		<?php 
        }
    }
示例#27
0
// Shipping
$include_files = array_merge($include_files, (array) glob(dirname(__FILE__) . "/shipping/*.php"));
// 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);
    }
}