function jigoshop_edit_address()
{
    $account_url = get_permalink(jigoshop_get_page_id(JIGOSHOP_MY_ACCOUNT));
    $user_id = get_current_user_id();
    $load_address = jigoshop_get_address_to_edit();
    $address = jigoshop_get_address_fields($load_address, $user_id);
    if (isset($_POST['save_address']) && jigoshop::verify_nonce(JIGOSHOP_EDIT_ADDRESS)) {
        if ($user_id > 0) {
            foreach ($address as &$field) {
                if (isset($_POST[$field['name']])) {
                    $field['value'] = jigowatt_clean($_POST[$field['name']]);
                    update_user_meta($user_id, $field['name'], $field['value']);
                }
            }
            do_action('jigoshop_user_edit_address', $user_id, $address);
        }
    }
    jigoshop_render('shortcode/my_account/edit_address', array('url' => add_query_arg('address', $load_address, apply_filters('jigoshop_get_edit_address_page_id', get_permalink(jigoshop_get_page_id(JIGOSHOP_EDIT_ADDRESS)))), 'account_url' => $account_url, 'load_address' => $load_address, 'address' => $address));
}
Esempio n. 2
0
/**
 * Format decimal numbers according to current settings.
 *
 * @param  float|string $number Expects either a float or a string with a decimal separator only (no thousands)
 * @param  mixed $dp number of decimal points to use, blank to use configured decimals or false to avoid all rounding.
 * @param  boolean $trim_zeros from end of string
 * @return string
 */
function jigoshop_format_decimal($number, $dp = false, $trim_zeros = false)
{
    $locale = localeconv();
    $options = Jigoshop_Base::get_options();
    $decimals = array($options->get('jigoshop_price_decimal_sep'), $locale['decimal_point'], $locale['mon_decimal_point']);
    // Remove locale from string
    if (!is_float($number)) {
        $number = jigowatt_clean(str_replace($decimals, '.', $number));
    }
    if ($dp !== false) {
        $dp = intval($dp == "" ? $options->get('jigoshop_price_num_decimals') : $dp);
        $number = number_format(floatval($number), $dp, '.', '');
        // DP is false - don't use number format, just return a string in our format
    } elseif (is_float($number)) {
        $number = jigowatt_clean(str_replace($decimals, '.', strval($number)));
    }
    if ($trim_zeros && strstr($number, '.')) {
        $number = rtrim(rtrim($number, '0'), '.');
    }
    return $number;
}
 /**
  * Validate the checkout
  */
 public function validate_checkout()
 {
     if (jigoshop_cart::is_empty()) {
         jigoshop::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>', 'jigoshop'), home_url()));
     }
     // Process Discount Codes
     if (!empty($_POST['coupon_code'])) {
         $coupon = sanitize_title($_POST['coupon_code']);
         jigoshop_cart::add_discount($coupon);
     }
     foreach (jigoshop_cart::get_coupons() as $coupon) {
         jigoshop_cart::is_valid_coupon($coupon);
     }
     // Checkout fields
     $this->posted['shipping_method'] = '';
     $this->posted['shipping_service'] = '';
     if (isset($_POST['shipping_method'])) {
         $shipping_method = jigowatt_clean($_POST['shipping_method']);
         $shipping_data = explode(':', $shipping_method);
         $this->posted['shipping_method'] = $shipping_data[0];
         $this->posted['shipping_service'] = $shipping_data[1];
     }
     $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : '';
     $this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : '';
     $this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : '';
     $this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : '';
     $this->posted['create_account'] = isset($_POST['create_account']) ? jigowatt_clean($_POST['create_account']) : '';
     $this->posted['account_username'] = isset($_POST['account_username']) ? jigowatt_clean($_POST['account_username']) : '';
     $this->posted['account_password'] = isset($_POST['account_password']) ? jigowatt_clean($_POST['account_password']) : '';
     $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? jigowatt_clean($_POST['account_password_2']) : '';
     if (jigoshop_cart::get_total(false) == 0) {
         $this->posted['payment_method'] = 'no_payment';
     }
     // establish customer billing and shipping locations
     if (jigoshop_cart::ship_to_billing_address_only()) {
         $this->posted['shiptobilling'] = 'true';
     }
     $country = isset($_POST['billing_country']) ? jigowatt_clean($_POST['billing_country']) : '';
     $state = isset($_POST['billing_state']) ? jigowatt_clean($_POST['billing_state']) : '';
     $allowed_countries = Jigoshop_Base::get_options()->get('jigoshop_allowed_countries');
     if ($allowed_countries === 'specific') {
         $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries');
         if (!in_array($country, $specific_countries)) {
             jigoshop::add_error(__('Invalid billing country.', 'jigoshop'));
             return;
         }
     }
     if (jigoshop_countries::country_has_states($country)) {
         $states = jigoshop_countries::get_states($country);
         if (!in_array($state, array_keys($states))) {
             jigoshop::add_error(__('Invalid billing state.', 'jigoshop'));
             return;
         }
     }
     $postcode = isset($_POST['billing_postcode']) ? jigowatt_clean($_POST['billing_postcode']) : '';
     $ship_to_billing = Jigoshop_Base::get_options()->get('jigoshop_ship_to_billing_address_only') == 'yes';
     jigoshop_customer::set_location($country, $state, $postcode);
     if (Jigoshop_Base::get_options()->get('jigoshop_calc_shipping') == 'yes') {
         if ($ship_to_billing || !empty($_POST['shiptobilling'])) {
             jigoshop_customer::set_shipping_location($country, $state, $postcode);
         } else {
             $country = isset($_POST['shipping_country']) ? jigowatt_clean($_POST['shipping_country']) : '';
             $state = isset($_POST['shipping_state']) ? jigowatt_clean($_POST['shipping_state']) : '';
             $postcode = isset($_POST['shipping_postcode']) ? jigowatt_clean($_POST['shipping_postcode']) : '';
             if ($allowed_countries === 'specific') {
                 $specific_countries = Jigoshop_Base::get_options()->get('jigoshop_specific_allowed_countries');
                 if (!in_array($country, $specific_countries)) {
                     jigoshop::add_error(__('Invalid shipping country.', 'jigoshop'));
                     return;
                 }
             }
             if (jigoshop_countries::country_has_states($country)) {
                 $states = jigoshop_countries::get_states($country);
                 if (!in_array($state, array_keys($states))) {
                     jigoshop::add_error(__('Invalid shipping state.', 'jigoshop'));
                     return;
                 }
             }
             jigoshop_customer::set_shipping_location($country, $state, $postcode);
         }
     }
     // Billing Information
     foreach ($this->billing_fields as $field) {
         $field = apply_filters('jigoshop_billing_field', $field);
         $this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : '';
         // Format
         if (isset($field['format'])) {
             switch ($field['format']) {
                 case 'postcode':
                     $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                     break;
             }
         }
         // Required
         if ($field['name'] == 'billing_state' && jigoshop_customer::has_valid_shipping_state()) {
             $field['required'] = false;
         }
         if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
             jigoshop::add_error($field['label'] . __(' (billing) is a required field.', 'jigoshop'));
         }
         if ($field['name'] == 'billing_euvatno') {
             $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : '';
             $vatno = str_replace(' ', '', $vatno);
             $country = jigoshop_tax::get_customer_country();
             // strip any country code from the beginning of the number
             if (strpos($vatno, $country) === 0) {
                 $vatno = substr($vatno, strlen($country));
             }
             if ($vatno != '') {
                 $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/';
                 $httpRequest = curl_init();
                 curl_setopt($httpRequest, CURLOPT_FAILONERROR, true);
                 curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($httpRequest, CURLOPT_HEADER, false);
                 curl_setopt($httpRequest, CURLOPT_URL, $url);
                 $result = curl_exec($httpRequest);
                 curl_close($httpRequest);
                 if ($result === 'false') {
                     jigoshop_log('EU VAT validation error with URL: ' . $url);
                     jigoshop::add_error($field['label'] . __(' (billing) is not a valid VAT Number.  Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'jigoshop'));
                 } else {
                     $this->valid_euvatno = jigoshop_countries::get_base_country() != jigoshop_tax::get_customer_country() && jigoshop_countries::is_eu_country(jigoshop_tax::get_customer_country());
                 }
             }
         }
         // Validation
         if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
             switch ($field['validate']) {
                 case 'phone':
                     if (!jigoshop_validation::is_phone($this->posted[$field['name']])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid number.', 'jigoshop'));
                     }
                     break;
                 case 'email':
                     if (!jigoshop_validation::is_email($this->posted[$field['name']])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid email address.', 'jigoshop'));
                     }
                     break;
                 case 'postcode':
                     if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) {
                         jigoshop::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'jigoshop'));
                     } else {
                         $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']);
                     }
                     break;
             }
         }
     }
     // Shipping Information
     if (jigoshop_shipping::is_enabled() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) {
         foreach ($this->shipping_fields as $field) {
             $field = apply_filters('jigoshop_shipping_field', $field);
             if (isset($_POST[$field['name']])) {
                 $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]);
             } else {
                 $this->posted[$field['name']] = '';
             }
             // Format
             if (isset($field['format'])) {
                 switch ($field['format']) {
                     case 'postcode':
                         $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']]));
                         break;
                 }
             }
             // Required
             if ($field['name'] == 'shipping_state' && jigoshop_customer::has_valid_shipping_state()) {
                 $field['required'] = false;
             }
             if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) {
                 jigoshop::add_error($field['label'] . __(' (shipping) is a required field.', 'jigoshop'));
             }
             // Validation
             if (isset($field['validate']) && !empty($this->posted[$field['name']])) {
                 switch ($field['validate']) {
                     case 'postcode':
                         if (!jigoshop_validation::is_postcode($this->posted[$field['name']], $country)) {
                             jigoshop::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'jigoshop'));
                         } else {
                             $this->posted[$field['name']] = jigoshop_validation::format_postcode($this->posted[$field['name']], $country);
                         }
                         break;
                 }
             }
         }
     }
     if ($this->must_register && empty($this->posted['create_account'])) {
         jigoshop::add_error(__('Sorry, you must agree to creating an account', 'jigoshop'));
     }
     if ($this->must_register || empty($user_id) && $this->posted['create_account']) {
         if (!$this->show_signup) {
             jigoshop::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'jigoshop'));
         }
         if (empty($this->posted['account_username'])) {
             jigoshop::add_error(__('Please enter an account username.', 'jigoshop'));
         }
         if (empty($this->posted['account_password'])) {
             jigoshop::add_error(__('Please enter an account password.', 'jigoshop'));
         }
         if ($this->posted['account_password_2'] !== $this->posted['account_password']) {
             jigoshop::add_error(__('Passwords do not match.', 'jigoshop'));
         }
         // Check the username
         if (!validate_username($this->posted['account_username'])) {
             jigoshop::add_error(__('Invalid email/username.', 'jigoshop'));
         } elseif (username_exists($this->posted['account_username'])) {
             jigoshop::add_error(__('An account is already registered with that username. Please choose another.', 'jigoshop'));
         }
         // Check the e-mail address
         if (email_exists($this->posted['billing_email'])) {
             jigoshop::add_error(__('An account is already registered with your email address. Please login.', 'jigoshop'));
         }
     }
     // Terms
     if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && jigoshop_get_page_id('terms') > 0) {
         jigoshop::add_error(__('You must accept our Terms &amp; Conditions.', 'jigoshop'));
     }
     if (jigoshop_cart::needs_shipping()) {
         // Shipping Method
         $available_methods = jigoshop_shipping::get_available_shipping_methods();
         if (!isset($available_methods[$this->posted['shipping_method']])) {
             jigoshop::add_error(__('Invalid shipping method.', 'jigoshop'));
         }
     }
 }
Esempio n. 4
0
	/**
	 * Admin Panel Options Processing
	 * - Saves the options to the DB
	 **/
    public function process_admin_options() {
   		if(isset($_POST['jigoshop_paypal_enabled'])) update_option('jigoshop_paypal_enabled', jigowatt_clean($_POST['jigoshop_paypal_enabled'])); else @delete_option('jigoshop_paypal_enabled');
   		if(isset($_POST['jigoshop_paypal_title'])) update_option('jigoshop_paypal_title', jigowatt_clean($_POST['jigoshop_paypal_title'])); else @delete_option('jigoshop_paypal_title');
   		if(isset($_POST['jigoshop_paypal_email'])) update_option('jigoshop_paypal_email', jigowatt_clean($_POST['jigoshop_paypal_email'])); else @delete_option('jigoshop_paypal_email');
   		if(isset($_POST['jigoshop_paypal_description'])) update_option('jigoshop_paypal_description', jigowatt_clean($_POST['jigoshop_paypal_description'])); else @delete_option('jigoshop_paypal_description');
   		if(isset($_POST['jigoshop_paypal_testmode'])) update_option('jigoshop_paypal_testmode', jigowatt_clean($_POST['jigoshop_paypal_testmode'])); else @delete_option('jigoshop_paypal_testmode');
   		if(isset($_POST['jigoshop_paypal_send_shipping'])) update_option('jigoshop_paypal_send_shipping', jigowatt_clean($_POST['jigoshop_paypal_send_shipping'])); else @delete_option('jigoshop_paypal_send_shipping');
    }
Esempio n. 5
0
	/**
	 * Admin Panel Options Processing
	 * - Saves the options to the DB
	 **/
    public function process_admin_options() {
   		if(isset($_POST['jigoshop_cheque_enabled'])) 	update_option('jigoshop_cheque_enabled', 	jigowatt_clean($_POST['jigoshop_cheque_enabled'])); else @delete_option('jigoshop_cheque_enabled');
   		if(isset($_POST['jigoshop_cheque_title'])) 	update_option('jigoshop_cheque_title', 	jigowatt_clean($_POST['jigoshop_cheque_title'])); else @delete_option('jigoshop_cheque_title');
   		if(isset($_POST['jigoshop_cheque_description'])) 	update_option('jigoshop_cheque_description', 	jigowatt_clean($_POST['jigoshop_cheque_description'])); else @delete_option('jigoshop_cheque_description');
    }
 /**
  * When Options are saved, return the 'jigoshop_tax_rates' option values
  *
  * @return  mixed  false if not rax rates, array of tax rates otherwise
  * @since  1.3
  */
 function get_updated_tax_classes()
 {
     $tax_rates = array();
     $tax_fields = array('tax_classes' => '', 'tax_country' => '', 'tax_rate' => '', 'tax_label' => '', 'tax_shipping' => '', 'tax_compound' => '');
     /* Save each array key to a variable */
     foreach ($tax_fields as $name => $val) {
         if (isset($_POST[$name])) {
             $tax_fields[$name] = $_POST[$name];
         }
     }
     for ($i = 0; $i < sizeof($tax_fields['tax_classes']); $i++) {
         if (empty($tax_fields['tax_rate'][$i])) {
             continue;
         }
         $countries = $tax_fields['tax_country'][$i];
         $label = trim($tax_fields['tax_label'][$i]);
         $rate = number_format(floatval($tax_fields['tax_rate'][$i]), 4);
         $class = jigowatt_clean($tax_fields['tax_classes'][$i]);
         $shipping = !empty($tax_fields['tax_shipping'][$i]) ? 'yes' : 'no';
         $compound = !empty($tax_fields['tax_compound'][$i]) ? 'yes' : 'no';
         /* Save the state & country separately from options eg US:OH */
         $whole_countries_processed = array();
         foreach ($countries as $country_code) {
             @(list($country, $state) = explode(':', $country_code, 2));
             if (!in_array($country, $whole_countries_processed)) {
                 if ($state === null && jigoshop_countries::country_has_states($country)) {
                     $whole_countries_processed[] = $country;
                     foreach (jigoshop_countries::get_states($country) as $state => $state_name) {
                         $tax_rates[] = array('country' => $country, 'label' => $label, 'state' => $state, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => true);
                     }
                 } else {
                     $tax_rates[] = array('country' => $country, 'label' => $label, 'state' => $state, 'rate' => $rate, 'shipping' => $shipping, 'class' => $class, 'compound' => $compound, 'is_all_states' => false);
                 }
             }
         }
     }
     usort($tax_rates, array($this, 'csort_tax_rates'));
     return $tax_rates;
 }
Esempio n. 7
0
	/**
	 * Admin Panel Options Processing - save options to the database.
	 **/
    public function process_admin_options() {
    
    	(isset($_POST['jigoshop_bank_transfer_enabled'])) ? update_option('jigoshop_bank_transfer_enabled', jigowatt_clean($_POST['jigoshop_bank_transfer_enabled'])) : @delete_option('jigoshop_bank_transfer_enabled');
    	
    	(isset($_POST['jigoshop_bank_transfer_title'])) ? update_option('jigoshop_bank_transfer_title', jigowatt_clean($_POST['jigoshop_bank_transfer_title'])) : @delete_option('jigoshop_bank_transfer_title');
    	
    	(isset($_POST['jigoshop_bank_transfer_description'])) ? update_option('jigoshop_bank_transfer_description', jigowatt_clean($_POST['jigoshop_bank_transfer_description'])) : @delete_option('jigoshop_bank_transfer_description');
    	
    	(isset($_POST['jigoshop_bank_transfer_bank_name'])) ? update_option('jigoshop_bank_transfer_bank_name', jigowatt_clean($_POST['jigoshop_bank_transfer_bank_name'])) : @delete_option('jigoshop_bank_transfer_bank_name');
    	
    	(isset($_POST['jigoshop_bank_transfer_acc_number'])) ? update_option('jigoshop_bank_transfer_acc_number', jigowatt_clean($_POST['jigoshop_bank_transfer_acc_number'])) : @delete_option('jigoshop_bank_transfer_acc_number');
    	
    	(isset($_POST['jigoshop_bank_transfer_sort_code'])) ? update_option('jigoshop_bank_transfer_sort_code', jigowatt_clean($_POST['jigoshop_bank_transfer_sort_code'])) : @delete_option('jigoshop_bank_transfer_sort_code');
    	
    	(isset($_POST['jigoshop_bank_transfer_iban'])) ? update_option('jigoshop_bank_transfer_iban', jigowatt_clean($_POST['jigoshop_bank_transfer_iban'])) : @delete_option('jigoshop_bank_transfer_iban');
    	
    	(isset($_POST['jigoshop_bank_transfer_bic'])) ? update_option('jigoshop_bank_transfer_bic', jigowatt_clean($_POST['jigoshop_bank_transfer_bic'])) : @delete_option('jigoshop_bank_transfer_bic');
    	
    	(isset($_POST['jigoshop_bank_transfer_additional'])) ? update_option('jigoshop_bank_transfer_additional', jigowatt_clean($_POST['jigoshop_bank_transfer_additional'])) : @delete_option('jigoshop_bank_transfer_additional');
    	
    }
Esempio n. 8
0
function jigoshop_process_shop_coupon_meta($post_id, $post)
{
    global $wpdb, $jigoshop_errors;
    $type = jigowatt_clean($_POST['type']);
    $amount = abs(jigowatt_clean($_POST['amount']));
    if (!empty($_POST['date_from'])) {
        $coupon_date_from = strtotime(jigowatt_clean($_POST['date_from']));
    } else {
        $coupon_date_from = '';
    }
    if (!empty($_POST['date_to'])) {
        $coupon_date_to = strtotime(jigowatt_clean($_POST['date_to'])) + (60 * 60 * 24 - 1);
    } else {
        $coupon_date_to = '';
    }
    $usage_limit = isset($_POST['usage_limit']) && $_POST['usage_limit'] > 0 ? (int) jigowatt_clean($_POST['usage_limit']) : '';
    $individual = isset($_POST['individual_use']);
    $free_shipping = isset($_POST['free_shipping']);
    $minimum_amount = jigowatt_clean($_POST['order_total_min']);
    $maximum_amount = jigowatt_clean($_POST['order_total_max']);
    if (isset($_POST['include_products'])) {
        $include_products = jigowatt_clean($_POST['include_products']);
        if ($include_products == 'Array') {
            $include_products = '';
        }
        $include_products = $include_products != '' ? explode(',', $include_products) : array();
    } else {
        $include_products = array();
    }
    if (isset($_POST['exclude_products'])) {
        $exclude_products = jigowatt_clean($_POST['exclude_products']);
        if ($exclude_products == 'Array') {
            $exclude_products = '';
        }
        $exclude_products = $exclude_products != '' ? explode(',', $exclude_products) : array();
    } else {
        $exclude_products = array();
    }
    if (isset($_POST['include_categories'])) {
        $include_categories = $_POST['include_categories'];
    } else {
        $include_categories = array();
    }
    if (isset($_POST['exclude_categories'])) {
        $exclude_categories = $_POST['exclude_categories'];
    } else {
        $exclude_categories = array();
    }
    if (isset($_POST['pay_methods'])) {
        $pay_methods = $_POST['pay_methods'];
    } else {
        $pay_methods = array();
    }
    update_post_meta($post_id, 'type', $type);
    update_post_meta($post_id, 'amount', $amount);
    update_post_meta($post_id, 'date_from', $coupon_date_from);
    update_post_meta($post_id, 'date_to', $coupon_date_to);
    update_post_meta($post_id, 'usage_limit', $usage_limit);
    update_post_meta($post_id, 'individual_use', $individual);
    update_post_meta($post_id, 'free_shipping', $free_shipping);
    update_post_meta($post_id, 'order_total_min', $minimum_amount);
    update_post_meta($post_id, 'order_total_max', $maximum_amount);
    update_post_meta($post_id, 'include_products', $include_products);
    update_post_meta($post_id, 'exclude_products', $exclude_products);
    update_post_meta($post_id, 'include_categories', $include_categories);
    update_post_meta($post_id, 'exclude_categories', $exclude_categories);
    update_post_meta($post_id, 'pay_methods', $pay_methods);
}
Esempio n. 9
0
    public function process_admin_options() {
   		
   		if(isset($_POST['jigoshop_free_shipping_enabled'])) update_option('jigoshop_free_shipping_enabled', jigowatt_clean($_POST['jigoshop_free_shipping_enabled'])); else @delete_option('jigoshop_free_shipping_enabled');
   		if(isset($_POST['jigoshop_free_shipping_title'])) update_option('jigoshop_free_shipping_title', jigowatt_clean($_POST['jigoshop_free_shipping_title'])); else @delete_option('jigoshop_free_shipping_title');
   		if(isset($_POST['jigoshop_free_shipping_minimum_amount'])) update_option('jigoshop_free_shipping_minimum_amount', jigowatt_clean($_POST['jigoshop_free_shipping_minimum_amount'])); else @delete_option('jigoshop_free_shipping_minimum_amount');
   		if(isset($_POST['jigoshop_free_shipping_availability'])) update_option('jigoshop_free_shipping_availability', jigowatt_clean($_POST['jigoshop_free_shipping_availability'])); else @delete_option('jigoshop_free_shipping_availability');
	    
	    if (isset($_POST['jigoshop_free_shipping_countries'])) $selected_countries = $_POST['jigoshop_free_shipping_countries']; else $selected_countries = array();
	    update_option('jigoshop_free_shipping_countries', $selected_countries);
   		
    }
Esempio n. 10
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;
}
/**
 * Update options
 * 
 * Updates the options on the jigoshop settings page.
 *
 * @since 		1.0
 * @usedby 		jigoshop_settings()
 *
 * @param 		array $options List of options to go through and save
 */
function jigoshop_update_options($options) {
    if(isset($_POST['submitted']) && $_POST['submitted'] == 'yes') {
        foreach ($options as $value) {
        	if (isset($value['id']) && $value['id']=='jigoshop_tax_rates') :
        	
        		$tax_classes = array();
        		$tax_countries = array();
        		$tax_rate = array();
        		$tax_rates = array();
        		$tax_shipping = array();

				if (isset($_POST['tax_class'])) $tax_classes = $_POST['tax_class'];
				if (isset($_POST['tax_country'])) $tax_countries = $_POST['tax_country'];
				if (isset($_POST['tax_rate'])) $tax_rate = $_POST['tax_rate'];
				if (isset($_POST['tax_shipping'])) $tax_shipping = $_POST['tax_shipping'];
				
				for ($i=0; $i<sizeof($tax_classes); $i++) :
				
					if (isset($tax_classes[$i]) && isset($tax_countries[$i]) && isset($tax_rate[$i]) && $tax_rate[$i] && is_numeric($tax_rate[$i])) :
						
						$country = jigowatt_clean($tax_countries[$i]);
						$state = '*';
						$rate = number_format(jigowatt_clean($tax_rate[$i]), 4);
						$class = jigowatt_clean($tax_classes[$i]);
						
						if (isset($tax_shipping[$i]) && $tax_shipping[$i]) $shipping = 'yes'; else $shipping = 'no';
						
						// Get state from country input if defined
						if (strstr($country, ':')) :
							$cr = explode(':', $country);
							$country = current($cr);
							$state = end($cr);
						endif;
						
						$tax_rates[] = array(
							'country' => $country,
							'state' => $state,
							'rate' => $rate,
							'shipping' => $shipping,
							'class' => $class
						); 
						
					endif;

				endfor;
				
				update_option($value['id'], $tax_rates);
				
			elseif (isset($value['id']) && $value['id']=='jigoshop_coupons') :
				
				$coupon_code = array();
        		$coupon_type = array();
        		$coupon_amount = array();
        		$product_ids = array();
        		$coupons = array();
				$individual = array();
				
				if (isset($_POST['coupon_code'])) $coupon_code = $_POST['coupon_code'];
				if (isset($_POST['coupon_type'])) $coupon_type = $_POST['coupon_type'];
				if (isset($_POST['coupon_amount'])) $coupon_amount = $_POST['coupon_amount'];
				if (isset($_POST['product_ids'])) $product_ids = $_POST['product_ids'];
				if (isset($_POST['individual'])) $individual = $_POST['individual'];
				
				for ($i=0; $i<sizeof($coupon_code); $i++) :
					
					if ( isset($coupon_code[$i]) && isset($coupon_type[$i]) && isset($coupon_amount[$i]) ) :
						
						$code = jigowatt_clean($coupon_code[$i]);
						$type = jigowatt_clean($coupon_type[$i]);
						$amount = jigowatt_clean($coupon_amount[$i]);
						
						if (isset($product_ids[$i]) && $product_ids[$i]) $products = array_map('trim', explode(',', $product_ids[$i])); else $products = array();
						
						if (isset($individual[$i]) && $individual[$i]) $individual_use = 'yes'; else $individual_use = 'no';
						
						if ($code && $type && $amount) :
							$coupons[$code] = array( 
								'code' => $code,
								'amount' => $amount,
								'type' => $type,
								'products' => $products,
								'individual_use' => $individual_use
							);
						endif;
						
					endif;

				endfor;
				
				update_option($value['id'], $coupons);
			
			elseif (isset($value['type']) && $value['type']=='multi_select_countries') :
			
				// Get countries array
				if (isset($_POST[$value['id']])) $selected_countries = $_POST[$value['id']]; else $selected_countries = array();
				update_option($value['id'], $selected_countries);
			
			/* price separators get a special treatment as they should allow a spaces (don't trim) */
			elseif ( isset($value['id']) && ( $value['id'] == 'jigoshop_price_thousand_sep' || $value['id'] == 'jigoshop_price_decimal_sep' ) ):
				
				if( isset( $_POST[ $value['id'] ] )  ) {
					update_option($value['id'], $_POST[$value['id']] );
				} else {
	                @delete_option($value['id']);
	            }
	            
        	else :
			    
        		if(isset($value['id']) && isset($_POST[$value['id']])) {
	            	update_option($value['id'], jigowatt_clean($_POST[$value['id']]));
	            } else {
	                @delete_option($value['id']);
	            }
            
	        endif;
	        
        }
        
        do_action('jigoshop_update_options');
        
        echo '<div id="message" class="updated fade"><p><strong>'.__('Your settings have been saved.','jigoshop').'</strong></p></div>';
    }
}
Esempio n. 12
0
function jigoshop_process_shop_order_meta($post_id)
{
    $jigoshop_options = Jigoshop_Base::get_options();
    $jigoshop_errors = array();
    $order = new jigoshop_order($post_id);
    // Get old data + attributes
    $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true));
    //Get old order items
    $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true));
    // Add/Replace data to array
    $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_euvatno', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state');
    $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax');
    /* Pre-fill the customer addresses */
    foreach ($customerDetails as $key) {
        $order_fields[] = $key;
        /* Checks if this is a new order from "Add Order" button */
        if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) {
            $data[$key] = get_user_meta($_POST['customer_user'], $key, true);
        }
    }
    //Check EUVAT Field
    if (!empty($data['billing_euvatno']) && !empty($data['billing_country'])) {
        $data['billing_euvatno'] = str_replace(' ', '', $data['billing_euvatno']);
    }
    //run stripslashes on all valid fields
    foreach ($order_fields as $field_name) {
        if (isset($_POST[$field_name])) {
            $data[$field_name] = stripslashes($_POST[$field_name]);
        }
    }
    // Sanitize numeric values
    $data['order_total'] = jigoshop_sanitize_num($data['order_total']);
    $data['order_subtotal'] = jigoshop_sanitize_num($data['order_subtotal']);
    // if a shipping or payment methods has changed, update the method title for pretty display
    if (isset($_POST['shipping_method'])) {
        $data['shipping_service'] = '';
        $shipping_methods = jigoshop_shipping::get_all_methods();
        if (!empty($shipping_methods)) {
            foreach ($shipping_methods as $method) {
                if ($_POST['shipping_method'] == $method->id) {
                    $data['shipping_service'] = $method->title;
                }
            }
        }
    }
    if (isset($_POST['payment_method'])) {
        $data['payment_method_title'] = '';
        $payment_methods = jigoshop_payment_gateways::get_available_payment_gateways();
        if (!empty($payment_methods)) {
            foreach ($payment_methods as $method) {
                if ($_POST['payment_method'] == $method->id) {
                    $data['payment_method_title'] = $method->title;
                }
            }
        }
    }
    // if total tax has been modified from order tax, then create a customized tax array
    // just for the order. At this point, we no longer know about multiple tax classes.
    // Even if we used the old tax array data, we still don't know how to break down
    // the amounts since they're customized.
    if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) {
        $new_tax = $data['order_tax_total'];
        $data['order_tax'] = jigoshop_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null);
    }
    // Customer
    update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']);
    // Order items
    $order_items = array();
    if (isset($_POST['item_id'])) {
        $item_id = $_POST['item_id'];
        $item_variation = $_POST['item_variation_id'];
        $item_name = $_POST['item_name'];
        $item_quantity = $_POST['item_quantity'];
        $item_cost = $_POST['item_cost'];
        $item_tax_rate = $_POST['item_tax_rate'];
        for ($i = 0; $i < count($item_id); $i++) {
            if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) {
                continue;
            }
            $variation_id = '';
            $variation = '';
            if (!empty($item_variation[$i])) {
                $variation_id = (int) $item_variation[$i];
                // if this is a variation, we should check if it is an old one
                // and copy the 'variation' field describing details of variation
                foreach ($old_order_items as $old_item_index => $old_item) {
                    if ($old_item['variation_id'] == $variation_id) {
                        $variation = $old_item['variation'];
                        unset($old_order_items[$old_item_index]);
                        break;
                    }
                }
                // override variation with values from $_POST
                if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) {
                    foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) {
                        $variation[$var_key] = $var_value;
                    }
                }
            }
            $cost_inc_tax = $jigoshop_options->get('jigoshop_prices_include_tax') == 'yes' ? number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', '') : -1;
            $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) jigowatt_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) jigowatt_clean($item_tax_rate[$i]), 4, '.', '')));
        }
    }
    // Process custom attributes added with "jigoshop_order_data_panels"
    $data = apply_filters("jigoshop_order_data_save", $data, $post_id);
    // Save
    update_post_meta($post_id, 'order_data', $data);
    update_post_meta($post_id, 'order_items', $order_items);
    // Order status
    $order->update_status($_POST['order_status']);
    // Handle button actions
    if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) {
        $order->add_order_note(__('Manually reducing stock.', 'jigoshop'));
        foreach ($order_items as $order_item) {
            $_product = $order->get_product_from_item($order_item);
            if ($_product->exists) {
                if ($_product->managing_stock()) {
                    $old_stock = $_product->stock;
                    $new_quantity = $_product->reduce_stock($order_item['qty']);
                    $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity));
                    if ($new_quantity < 0) {
                        if ($old_stock < 0) {
                            $backorder_qty = $order_item['qty'];
                        } else {
                            $backorder_qty = $old_stock - $order_item['qty'];
                        }
                        do_action('jigoshop_product_on_backorder_notification', $post_id, $_product, $backorder_qty);
                    }
                    // stock status notifications
                    if ($jigoshop_options->get('jigoshop_notify_no_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= 0 && $jigoshop_options->get('jigoshop_notify_no_stock_amount') >= $new_quantity) {
                        do_action('jigoshop_no_stock_notification', $_product);
                    } else {
                        if ($jigoshop_options->get('jigoshop_notify_low_stock') == 'yes' && $jigoshop_options->get('jigoshop_notify_low_stock_amount') >= $new_quantity) {
                            do_action('jigoshop_low_stock_notification', $_product);
                        }
                    }
                }
            } else {
                $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name']));
            }
        }
        $order->add_order_note(__('Manual stock reduction complete.', 'jigoshop'));
    } else {
        if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) {
            $order->add_order_note(__('Manually restoring stock.', 'jigoshop'));
            foreach ($order_items as $order_item) {
                $_product = $order->get_product_from_item($order_item);
                if ($_product->exists) {
                    if ($_product->managing_stock()) {
                        $old_stock = $_product->stock;
                        $new_quantity = $_product->increase_stock($order_item['qty']);
                        $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity));
                    }
                } else {
                    $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name']));
                }
            }
            $order->add_order_note(__('Manual stock restore complete.', 'jigoshop'));
        } else {
            if (isset($_POST['invoice']) && $_POST['invoice']) {
                // Mail link to customer
                jigoshop_send_customer_invoice($order->id);
            }
        }
    }
    // Error Handling
    if (count($jigoshop_errors) > 0) {
        $jigoshop_options->set('jigoshop_errors', $jigoshop_errors);
    }
}
	/** Process the checkout after the confirm order button is pressed */
	function process_checkout() {
	
		global $wpdb;
		
		do_action('jigoshop_before_checkout_process');
		
		if (isset($_POST) && $_POST && !isset($_POST['login'])) :

			jigoshop_cart::calculate_totals();
			
			jigoshop::verify_nonce('process_checkout');
			
			if (sizeof(jigoshop_cart::$cart_contents)==0) :
				jigoshop::add_error( sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>','jigoshop'), home_url()) );
			endif;
						
			// Checkout fields
			$this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? jigowatt_clean($_POST['shiptobilling']) : '';
			$this->posted['payment_method'] = isset($_POST['payment_method']) ? jigowatt_clean($_POST['payment_method']) : '';
			$this->posted['shipping_method'] = isset($_POST['shipping_method']) ? jigowatt_clean($_POST['shipping_method']) : '';
			$this->posted['order_comments'] = isset($_POST['order_comments']) ? jigowatt_clean($_POST['order_comments']) : '';
			$this->posted['terms'] = isset($_POST['terms']) ? jigowatt_clean($_POST['terms']) : '';
			$this->posted['createaccount'] = isset($_POST['createaccount']) ? jigowatt_clean($_POST['createaccount']) : '';
			$this->posted['account-username'] = isset($_POST['account-username']) ? jigowatt_clean($_POST['account-username']) : '';
			$this->posted['account-password'] = isset($_POST['account-password']) ? jigowatt_clean($_POST['account-password']) : '';
			$this->posted['account-password-2'] = isset($_POST['account-password-2']) ? jigowatt_clean($_POST['account-password-2']) : '';
			
			if (jigoshop_cart::ship_to_billing_address_only()) $this->posted['shiptobilling'] = 'true';
			
			// Billing Information
			foreach ($this->billing_fields as $field) :
				
				$this->posted[$field['name']] = isset($_POST[$field['name']]) ? jigowatt_clean($_POST[$field['name']]) : '';
				
				// Format
				if (isset($field['format'])) switch ( $field['format'] ) :
					case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break;
				endswitch;
				
				// Required
				if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (billing) is a required field.','jigoshop') );
	
				// Validation
				if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) :
					case 'phone' :
						if (!jigoshop_validation::is_phone( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid number.','jigoshop') ); endif;
					break;
					case 'email' :
						if (!jigoshop_validation::is_email( $this->posted[$field['name']] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid email address.','jigoshop') ); endif;
					break;
					case 'postcode' :
						if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $_POST['billing-country'] )) : jigoshop::add_error( $field['label'] . __(' (billing) is not a valid postcode/ZIP.','jigoshop') ); 
						else :
							$this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $_POST['billing-country'] );
						endif;
					break;
				endswitch;
				
			endforeach;
			
			// Shipping Information
			if (jigoshop_cart::needs_shipping() && !jigoshop_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) :
				
				foreach ($this->shipping_fields as $field) :
					if (isset( $_POST[$field['name']] )) $this->posted[$field['name']] = jigowatt_clean($_POST[$field['name']]); else $this->posted[$field['name']] = '';
					
					// Format
					if (isset($field['format'])) switch ( $field['format'] ) :
						case 'postcode' : $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break;
					endswitch;
					
					// Required
					if ( isset($field['required']) && $field['required'] && empty($this->posted[$field['name']]) ) jigoshop::add_error( $field['label'] . __(' (shipping) is a required field.','jigoshop') );
		
					// Validation
					if (isset($field['validate']) && !empty($this->posted[$field['name']])) switch ( $field['validate'] ) :
						case 'postcode' :
							if (!jigoshop_validation::is_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] )) : jigoshop::add_error( $field['label'] . __(' (shipping) is not a valid postcode/ZIP.','jigoshop') ); 
							else :
								$this->posted[$field['name']] = jigoshop_validation::format_postcode( $this->posted[$field['name']], $this->posted['shipping-country'] );
							endif;
						break;
					endswitch;
					
				endforeach;
			
			endif;

			if (is_user_logged_in()) :
				$this->creating_account = false;
			elseif (isset($this->posted['createaccount']) && $this->posted['createaccount']) :
				$this->creating_account = true;
			elseif ($this->must_create_account) :
				$this->creating_account = true;
			else :
				$this->creating_account = false;
			endif;
			
			if ($this->creating_account && !$user_id) :
			
				if ( empty($this->posted['account-username']) ) jigoshop::add_error( __('Please enter an account username.','jigoshop') );
				if ( empty($this->posted['account-password']) ) jigoshop::add_error( __('Please enter an account password.','jigoshop') );
				if ( $this->posted['account-password-2'] !== $this->posted['account-password'] ) jigoshop::add_error( __('Passwords do not match.','jigoshop') );
			
				// Check the username
				if ( !validate_username( $this->posted['account-username'] ) ) :
					jigoshop::add_error( __('Invalid email/username.','jigoshop') );
				elseif ( username_exists( $this->posted['account-username'] ) ) :
					jigoshop::add_error( __('An account is already registered with that username. Please choose another.','jigoshop') );
				endif;
				
				// Check the e-mail address
				if ( email_exists( $this->posted['billing-email'] ) ) :
					jigoshop::add_error( __('An account is already registered with your email address. Please login.','jigoshop') );
				endif;
			endif;
			
			// Terms
			if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && get_option('jigoshop_terms_page_id')>0 ) jigoshop::add_error( __('You must accept our Terms &amp; Conditions.','jigoshop') );
			
			if (jigoshop_cart::needs_shipping()) :
			
				// Shipping Method
				$available_methods = jigoshop_shipping::get_available_shipping_methods();
				if (!isset($available_methods[$this->posted['shipping_method']])) :
					jigoshop::add_error( __('Invalid shipping method.','jigoshop') );
				endif;	
			
			endif;	
			
			if (jigoshop_cart::needs_payment()) :
				// Payment Method
				$available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
				if (!isset($available_gateways[$this->posted['payment_method']])) :
					jigoshop::add_error( __('Invalid payment method.','jigoshop') );
				else :
					// Payment Method Field Validation
					$available_gateways[$this->posted['payment_method']]->validate_fields();
				endif;
			endif;
					
			if (!isset($_POST['update_totals']) && jigoshop::error_count()==0) :
				
				$user_id = get_current_user_id();
				
				while (1) :
					
					// Create customer account and log them in
					if ($this->creating_account && !$user_id) :
				
						$reg_errors = new WP_Error();
						do_action('register_post', $this->posted['billing-email'], $this->posted['billing-email'], $reg_errors);
						$errors = apply_filters( 'registration_errors', $reg_errors, $this->posted['billing-email'], $this->posted['billing-email'] );
				
		                // if there are no errors, let's create the user account
						if ( !$reg_errors->get_error_code() ) :
		
			                $user_pass = $this->posted['account-password'];
			                $user_id = wp_create_user( $this->posted['account-username'], $user_pass, $this->posted['billing-email'] );
			                if ( !$user_id ) {
			                	jigoshop::add_error( sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'jigoshop'), get_option('admin_email')));
			                    break;
			                }
		
		                    // Change role
		                    wp_update_user( array ('ID' => $user_id, 'role' => 'customer') ) ;
		
		                    // send the user a confirmation and their login details
		                    wp_new_user_notification( $user_id, $user_pass );
		
		                    // set the WP login cookie
		                    $secure_cookie = is_ssl() ? true : false;
		                    wp_set_auth_cookie($user_id, true, $secure_cookie);
						
						else :
							jigoshop::add_error( $reg_errors->get_error_message() );
		                	break;                    
						endif;
						
					endif;

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

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

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

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

					if (jigoshop_cart::needs_payment()) :
						
						// Store Order ID in session so it can be re-used after payment failure
						$_SESSION['order_awaiting_payment'] = $order_id;
					
						// Process Payment
						$result = $available_gateways[$this->posted['payment_method']]->process_payment( $order_id );
						
						// Redirect to success/confirmation/payment page
						if ($result['result']=='success') :
						
							if (is_ajax()) : 
								ob_clean();
								echo json_encode($result);
								exit;
							else :
								wp_safe_redirect( $result['redirect'] );
								exit;
							endif;
							
						endif;
					
					else :
					
						// No payment was required for order
						$order->payment_complete();
						
						// Empty the Cart
						jigoshop_cart::empty_cart();
						
						// Redirect to success/confirmation/payment page
						if (is_ajax()) : 
							ob_clean();
							echo json_encode( array('redirect'	=> get_permalink(get_option('jigoshop_thanks_page_id'))) );
							exit;
						else :
							wp_safe_redirect( get_permalink(get_option('jigoshop_thanks_page_id')) );
							exit;
						endif;
						
					endif;
					
					// Break out of loop
					break;
				
				endwhile;
	
			endif;
			
			// If we reached this point then there were errors
			if (is_ajax()) : 
				ob_clean();
				jigoshop::show_messages();
				exit;
			else :
				jigoshop::show_messages();
			endif;
		
		endif;
	}
function jigoshop_update_coupons()
{
    /* Only grabbing this so as not to override the 'usage' field for a coupon when saving settings */
    $original_coupons = get_option('jigoshop_coupons');
    $couponFields = array('coupon_code' => '', 'coupon_type' => '', 'coupon_amount' => '', 'usage_limit' => '', 'product_ids' => '', 'exclude_product_ids' => '', 'exclude_categories' => '', 'coupon_category' => '', 'coupon_date_from' => '', 'coupon_date_to' => '', 'individual' => '', 'coupon_free_shipping' => '', 'coupon_pay_methods' => '', 'order_total_min' => '', 'order_total_max' => '');
    $coupons = array();
    /* Save each array key to a variable */
    foreach ($couponFields as $name => $val) {
        if (isset($_POST[$name])) {
            $couponFields[$name] = $_POST[$name];
        }
    }
    extract($couponFields);
    for ($i = 0; $i < sizeof($coupon_code); $i++) {
        if (empty($coupon_code[$i]) || !is_numeric($coupon_amount[$i])) {
            continue;
        }
        $amount = jigowatt_clean($coupon_amount[$i]);
        $code = jigowatt_clean($coupon_code[$i]);
        $type = jigowatt_clean($coupon_type[$i]);
        $limit = !empty($usage_limit[$i]) ? $usage_limit[$i] : 0;
        $min_order = !empty($order_total_min[$i]) ? $order_total_min[$i] : 0;
        $max_order = !empty($order_total_max[$i]) ? $order_total_max[$i] : 0;
        $from_date = !empty($coupon_date_from[$i]) ? strtotime($coupon_date_from[$i]) : 0;
        $free_ship = !empty($coupon_free_shipping[$i]) ? 'yes' : 'no';
        $individual_use = !empty($individual[$i]) ? 'yes' : 'no';
        $payments = !empty($coupon_pay_methods[$i]) ? $coupon_pay_methods[$i] : array();
        $category = !empty($coupon_category[$i]) ? $coupon_category[$i] : array();
        $products = !empty($product_ids[$i]) ? $product_ids[$i] : array();
        $ex_products = !empty($exclude_product_ids[$i]) ? $exclude_product_ids[$i] : array();
        $ex_categories = !empty($exclude_categories[$i]) ? $exclude_categories[$i] : array();
        $to_date = !empty($coupon_date_to[$i]) ? strtotime($coupon_date_to[$i]) + (60 * 60 * 24 - 1) : 0;
        if ($code && $type && $amount) {
            $coupons[$code] = array('code' => $code, 'amount' => $amount, 'type' => $type, 'products' => $products, 'exclude_products' => $ex_products, 'exclude_categories' => $ex_categories, 'coupon_pay_methods' => $payments, 'coupon_category' => $category, 'date_from' => $from_date, 'date_to' => $to_date, 'individual_use' => $individual_use, 'coupon_free_shipping' => $free_ship, 'usage_limit' => $limit, 'order_total_min' => $min_order, 'order_total_max' => $max_order, 'usage' => !empty($original_coupons[$code]['usage']) ? $original_coupons[$code]['usage'] : 0);
        }
    }
    update_option('jigoshop_coupons', $coupons);
}
Esempio n. 15
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;
}
Esempio n. 16
0
    public function process_admin_options() {

   		if(isset($_POST['jigoshop_flat_rate_tax_status'])) update_option('jigoshop_flat_rate_tax_status', jigowatt_clean($_POST['jigoshop_flat_rate_tax_status'])); else @delete_option('jigoshop_flat_rate_tax_status');
   		
   		if(isset($_POST['jigoshop_flat_rate_enabled'])) update_option('jigoshop_flat_rate_enabled', jigowatt_clean($_POST['jigoshop_flat_rate_enabled'])); else @delete_option('jigoshop_flat_rate_enabled');
   		if(isset($_POST['jigoshop_flat_rate_title'])) update_option('jigoshop_flat_rate_title', jigowatt_clean($_POST['jigoshop_flat_rate_title'])); else @delete_option('jigoshop_flat_rate_title');
   		if(isset($_POST['jigoshop_flat_rate_type'])) update_option('jigoshop_flat_rate_type', jigowatt_clean($_POST['jigoshop_flat_rate_type'])); else @delete_option('jigoshop_flat_rate_type');
   		if(isset($_POST['jigoshop_flat_rate_cost'])) update_option('jigoshop_flat_rate_cost', jigowatt_clean($_POST['jigoshop_flat_rate_cost'])); else @delete_option('jigoshop_flat_rate_cost');
   		if(isset($_POST['jigoshop_flat_rate_handling_fee'])) update_option('jigoshop_flat_rate_handling_fee', jigowatt_clean($_POST['jigoshop_flat_rate_handling_fee'])); else @delete_option('jigoshop_flat_rate_handling_fee');
   		
   		if(isset($_POST['jigoshop_flat_rate_availability'])) update_option('jigoshop_flat_rate_availability', jigowatt_clean($_POST['jigoshop_flat_rate_availability'])); else @delete_option('jigoshop_flat_rate_availability');	    
	    if (isset($_POST['jigoshop_flat_rate_countries'])) $selected_countries = $_POST['jigoshop_flat_rate_countries']; else $selected_countries = array();
	    update_option('jigoshop_flat_rate_countries', $selected_countries);
   		
    }
Esempio n. 17
0
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;
        }
    }
}
Esempio n. 18
0
function jigoshop_process_shop_order_meta( $post_id, $post ) {
	global $wpdb;
	
	$jigoshop_errors = array();
	
	$order = &new jigoshop_order($post_id);
	
	// Get old data + attributes
		$data = (array) maybe_unserialize( get_post_meta($post_id, 'order_data', true) );
	
	// Add/Replace data to array
		$data['billing_first_name'] 	= stripslashes( $_POST['billing_first_name'] );
		$data['billing_last_name'] 		= stripslashes( $_POST['billing_last_name'] );
		$data['billing_company'] 		= stripslashes( $_POST['billing_company'] );
		$data['billing_address_1'] 		= stripslashes( $_POST['billing_address_1'] );
		$data['billing_address_2']		= stripslashes( $_POST['billing_address_2'] );
		$data['billing_city']			= stripslashes( $_POST['billing_city'] );
		$data['billing_postcode'] 		= stripslashes( $_POST['billing_postcode'] );
		$data['billing_country']		= stripslashes( $_POST['billing_country'] );
		$data['billing_state'] 			= stripslashes( $_POST['billing_state'] );
		$data['billing_email']			= stripslashes( $_POST['billing_email'] );
		$data['billing_phone'] 			= stripslashes( $_POST['billing_phone'] );
		$data['shipping_first_name']	= stripslashes( $_POST['shipping_first_name'] );
		$data['shipping_last_name'] 	= stripslashes( $_POST['shipping_last_name'] );
		$data['shipping_company'] 		= stripslashes( $_POST['shipping_company'] );
		$data['shipping_address_1'] 	= stripslashes( $_POST['shipping_address_1'] );
		$data['shipping_address_2'] 	= stripslashes( $_POST['shipping_address_2'] );
		$data['shipping_city'] 			= stripslashes( $_POST['shipping_city'] );
		$data['shipping_postcode'] 		= stripslashes( $_POST['shipping_postcode'] );
		$data['shipping_country'] 		= stripslashes( $_POST['shipping_country'] );
		$data['shipping_state'] 		= stripslashes( $_POST['shipping_state'] );
		
		$data['shipping_method']		= stripslashes( $_POST['shipping_method'] );
		$data['payment_method'] 		= stripslashes( $_POST['payment_method'] );
		$data['order_subtotal'] 		= stripslashes( $_POST['order_subtotal'] );
		$data['order_shipping']			= stripslashes( $_POST['order_shipping'] );
		$data['order_discount'] 		= stripslashes( $_POST['order_discount'] );
		$data['order_tax'] 				= stripslashes( $_POST['order_tax'] );
		$data['order_shipping_tax'] 	= stripslashes( $_POST['order_shipping_tax'] );
		$data['order_total'] 			= stripslashes( $_POST['order_total'] );
	
	// Customer
		update_post_meta( $post_id, 'customer_user', (int) $_POST['customer_user'] );
	
	// Order status
		$order->update_status( $_POST['order_status'] );
	
	// Order items
		$order_items = array();
	
		if (isset($_POST['item_id'])) :
			 $item_id		= $_POST['item_id'];
			 $item_name 	= $_POST['item_name'];
			 $item_quantity = $_POST['item_quantity'];
			 $item_cost 	= $_POST['item_cost'];
			 $item_tax_rate = $_POST['item_tax_rate'];
	
			 for ($i=0; $i<sizeof($item_id); $i++) :
			 	
			 	if (!isset($item_id[$i])) continue;
			 	if (!isset($item_name[$i])) continue;
			 	if (!isset($item_quantity[$i])) continue;
			 	if (!isset($item_cost[$i])) continue;
			 	if (!isset($item_tax_rate[$i])) continue;
			 	
			 	$order_items[] = array(
			 		'id' 		=> htmlspecialchars(stripslashes($item_id[$i])),
			 		'name' 		=> htmlspecialchars(stripslashes($item_name[$i])),
			 		'qty' 		=> (int) $item_quantity[$i],
			 		'cost' 		=> number_format(jigowatt_clean($item_cost[$i]), 2),
			 		'taxrate' 	=> number_format(jigowatt_clean($item_tax_rate[$i]), 4)
			 	);

			 endfor; 
		endif;	
	
	// Save
		update_post_meta( $post_id, 'order_data', $data );
		update_post_meta( $post_id, 'order_items', $order_items );
	
	
	// Handle button actions
	
		if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && sizeof($order_items)>0) :
			
			$order->add_order_note( __('Manually reducing stock.', 'jigoshop') );
			
			foreach ($order_items as $order_item) :
						
				$_product = &new jigoshop_product( $order_item['id'] );
				
				if ($_product->exists) :
				
				 	if ($_product->managing_stock()) :
						
						$old_stock = $_product->stock;
						
						$new_quantity = $_product->reduce_stock( $order_item['qty'] );
						
						$order->add_order_note( sprintf( __('Item #%s stock reduced from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity) );
							
						if ($new_quantity<0) :
							do_action('jigoshop_product_on_backorder_notification', $order_item['id'], $values['quantity']);
						endif;
						
						// stock status notifications
						if (get_option('jigoshop_notify_no_stock_amount') && get_option('jigoshop_notify_no_stock_amount')>=$new_quantity) :
							do_action('jigoshop_no_stock_notification', $order_item['id']);
						elseif (get_option('jigoshop_notify_low_stock_amount') && get_option('jigoshop_notify_low_stock_amount')>=$new_quantity) :
							do_action('jigoshop_low_stock_notification', $order_item['id']);
						endif;
						
					endif;
				
				else :
					
					$order->add_order_note( sprintf( __('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'] ) );
					
				endif;
			 	
			endforeach;
			
			$order->add_order_note( __('Manual stock reduction complete.', 'jigoshop') );
			
		elseif (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items)>0) :
		
			$order->add_order_note( __('Manually restoring stock.', 'jigoshop') );
			
			foreach ($order_items as $order_item) :
						
				$_product = &new jigoshop_product( $order_item['id'] );
				
				if ($_product->exists) :
				
				 	if ($_product->managing_stock()) :
						
						$old_stock = $_product->stock;
						
						$new_quantity = $_product->increase_stock( $order_item['qty'] );
						
						$order->add_order_note( sprintf( __('Item #%s stock increased from %s to %s.', 'jigoshop'), $order_item['id'], $old_stock, $new_quantity) );
						
					endif;
				
				else :
					
					$order->add_order_note( sprintf( __('Item %s %s not found, skipping.', 'jigoshop'), $order_item['id'], $order_item['name'] ) );
					
				endif;
			 	
			endforeach;
			
			$order->add_order_note( __('Manual stock restore complete.', 'jigoshop') );
		
		elseif (isset($_POST['invoice']) && $_POST['invoice']) :
			
			// Mail link to customer
			jigoshop_pay_for_order_customer_notification( $order->id );
			
		endif;
	
	// Error Handling
		if (sizeof($jigoshop_errors)>0) update_option('jigoshop_errors', $jigoshop_errors);
}
Esempio n. 19
0
        $posting['wp_remote_post']['note'] .= ' ' . sprintf(__('Status code: %s', 'jigoshop'), jigowatt_clean($response['response']['code']));
    }
    $posting['wp_remote_post']['success'] = false;
}
// WP Remote Get Check
$posting['wp_remote_get']['name'] = __('Remote Get', 'jigoshop');
$posting['wp_remote_get']['help'] = '<a href="#" class="help_tip" data-tip="' . esc_attr__('Jigoshop plugins may use this method of communication when checking for plugin updates.', 'jigoshop') . '">[?]</a>';
$response = wp_remote_get('http://www.woothemes.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0'));
if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
    $posting['wp_remote_get']['success'] = true;
} else {
    $posting['wp_remote_get']['note'] = __('wp_remote_get() failed. The jigoshop plugin updater won\'t work with your server. Contact your hosting provider.', 'jigoshop');
    if (is_wp_error($response)) {
        $posting['wp_remote_get']['note'] .= ' ' . sprintf(__('Error: %s', 'jigoshop'), jigowatt_clean($response->get_error_message()));
    } else {
        $posting['wp_remote_get']['note'] .= ' ' . sprintf(__('Status code: %s', 'jigoshop'), jigowatt_clean($response['response']['code']));
    }
    $posting['wp_remote_get']['success'] = false;
}
$posting = apply_filters('jigoshop_debug_posting', $posting);
foreach ($posting as $post) {
    $mark = !empty($post['success']) ? 'yes' : 'error';
    ?>
			<tr>
				<td data-export-label="<?php 
    echo esc_html($post['name']);
    ?>
"><?php 
    echo esc_html($post['name']);
    ?>
:</td>
Esempio n. 20
0
	/**
	 * Admin Panel Options Processing
	 * - Saves the options to the DB
	 **/
    public function process_admin_options() {
   		if(isset($_POST['jigoshop_skrill_enabled'])) update_option('jigoshop_skrill_enabled', jigowatt_clean($_POST['jigoshop_skrill_enabled'])); else @delete_option('jigoshop_skrill_enabled');
   		if(isset($_POST['jigoshop_skrill_title'])) update_option('jigoshop_skrill_title', jigowatt_clean($_POST['jigoshop_skrill_title'])); else @delete_option('jigoshop_skrill_title');
   		if(isset($_POST['jigoshop_skrill_email'])) update_option('jigoshop_skrill_email', jigowatt_clean($_POST['jigoshop_skrill_email'])); else @delete_option('jigoshop_skrill_email');
   		if(isset($_POST['jigoshop_skrill_secret_word'])) update_option('jigoshop_skrill_secret_word', jigowatt_clean($_POST['jigoshop_skrill_secret_word'])); else @delete_option('jigoshop_skrill_secret_word');
   		if(isset($_POST['jigoshop_skrill_customer_id'])) update_option('jigoshop_skrill_customer_id', jigowatt_clean($_POST['jigoshop_skrill_customer_id'])); else @delete_option('jigoshop_skrill_customer_id');
    }