/** * wpsc_display_form_fields() * * This function displays each of the form fields. Each of them are filterable via 'wpsc_account_form_field_$tag' where tag is permalink-styled name or uniquename. * i.e. First Name under Shipping would be 'wpsc_account_form_field_shippingfirstname' - while Your Billing Details would be filtered * via 'wpsc_account_form_field_your-billing-details'. * * @global <type> $wpdb * @global <type> $user_ID * @global <type> $wpsc_purchlog_statuses * @global <type> $gateway_checkout_form_fields */ function wpsc_display_form_fields() { // Field display and Data saving function global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $wpsc_checkout; if (empty($wpsc_checkout)) { $wpsc_checkout = new wpsc_checout(); } $meta_data = wpsc_get_customer_meta('checkout_details'); $meta_data = apply_filters('wpsc_user_log_get', $meta_data, $user_ID); $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' ORDER BY `checkout_set`, `checkout_order`;"; $form_data = $wpdb->get_results($form_sql, ARRAY_A); foreach ($form_data as $form_field) { if (!empty($form_field['unique_name'])) { $ff_tag = $form_field['unique_name']; } else { $ff_tag = esc_html(strtolower(str_replace(' ', '-', $form_field['name']))); } if (!empty($meta_data[$form_field['id']]) && !is_array($meta_data[$form_field['id']])) { $meta_data[$form_field['id']] = esc_html($meta_data[$form_field['id']]); } if ($form_field['type'] == 'heading') { echo "\n <tr>\n <td colspan='2'>\n\r"; echo "<strong>" . apply_filters('wpsc_account_form_field_' . $ff_tag, esc_html($form_field['name'])) . "</strong>"; echo "\n </td>\n </tr>\n\r"; } else { $display = ''; if (in_array($form_field['unique_name'], array('shippingstate', 'billingstate'))) { if ($form_field['unique_name'] == 'shippingstate') { $country_field_id = wpsc_get_country_form_id_by_type('delivery_country'); } else { $country_field_id = wpsc_get_country_form_id_by_type('country'); } $country = is_array($meta_data[$country_field_id]) ? $meta_data[$country_field_id][0] : $meta_data[$country_field_id]; if (wpsc_has_regions($country)) { $display = ' style="display:none;"'; } } echo "\n\t\t <tr{$display}>\n \t\t <td align='left'>\n\r"; echo apply_filters('wpsc_account_form_field_' . $ff_tag, $form_field['name']); if ($form_field['mandatory'] == 1) { echo " *"; } echo "\n \t\t</td>\n\r\n \t\t<td align='left'>\n\r"; switch ($form_field['type']) { case "city": case "delivery_city": echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "address": case "delivery_address": case "textarea": echo "<textarea name='collected_data[" . $form_field['id'] . "]'>" . $meta_data[$form_field['id']] . "</textarea>"; break; case "text": $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : ''; echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "region": case "delivery_region": echo "<select name='collected_data[" . $form_field['id'] . "]'>" . nzshpcrt_region_list($_SESSION['collected_data'][$form_field['id']]) . "</select>"; break; case "country": if (is_array($meta_data[$form_field['id']])) { $country_code = $meta_data[$form_field['id']][0]; } else { $country_code = $meta_data[$form_field['id']]; } $html_id = 'wpsc-profile-billing-country'; $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\""; echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>"; if (wpsc_has_regions($country_code)) { $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : ''; echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>"; } break; case "delivery_country": if (is_array($meta_data[$form_field['id']])) { $country_code = $meta_data[$form_field['id']][0]; } else { $country_code = $meta_data[$form_field['id']]; } $html_id = 'wpsc-profile-shipping-country'; $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\""; echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>"; if (wpsc_has_regions($country_code)) { $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : ''; echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>"; } break; case "email": echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "select": $options = $wpsc_checkout->get_checkout_options($form_field['id']); $selected = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : null; ?> <select name='collected_data[<?php echo esc_attr($form_field['id']); ?> ]'> <option value="-1"><?php _ex('Select an Option', 'Dropdown default on user log page', 'wpsc'); ?> </option> <?php foreach ($options as $label => $value) { ?> <option <?php selected($value, $selected); ?> value="<?php echo esc_attr($value); ?> "><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php break; case 'checkbox': case 'radio': $checked_values = isset($meta_data[$form_field['id']]) ? (array) $meta_data[$form_field['id']] : array(); $options = $wpsc_checkout->get_checkout_options($form_field['id']); $field_name = "collected_data[{$form_field['id']}]"; if ($form_field['type'] == 'checkbox') { $field_name .= '[]'; } foreach ($options as $label => $value) { ?> <label> <input <?php checked(in_array($value, $checked_values)); ?> type="<?php echo $form_field['type']; ?> " id="" name="collected_data[<?php echo esc_attr($form_field['id']); ?> ][]" value="<?php echo esc_attr($value); ?> " /> <?php echo esc_html($label); ?> </label><br /> <?php } break; default: $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : ''; echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />"; break; } echo wp_nonce_field('wpsc_user_profile', '_wpsc_user_profile'); echo "\n </td>\n </tr>\n\r"; } } /* Returns an empty array at this point, empty in regards to fields, does show the internalname though. Needs to be reconsidered, even if it did work, need to check * functionality and PCI_DSS compliance if ( isset( $gateway_checkout_form_fields ) ) { echo $gateway_checkout_form_fields; } */ }
function wpsc_disregard_billing_state_fields() { global $wpsc_checkout; if ('billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions(wpsc_get_customer_meta('billingcountry'))) { return true; } return false; }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout() { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; //echo "break redirect"; // do_action('wpsc_before_submit_checkout'); $_SESSION['wpsc_checkout_misc_error_messages'] = array(); $wpsc_checkout = new wpsc_checkout(); //exit('coupons:'.$wpsc_cart->coupons_name); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = $_POST['custom_gateway']; $options = get_option('custom_shipping_options'); $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $wpsc_cart->uses_shipping) { $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } if ($_POST['agree'] != 'yes') { $_SESSION['wpsc_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } $selectedCountry = $wpdb->get_results("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape($_SESSION['wpsc_delivery_country']) . "'", ARRAY_A); foreach ($wpsc_cart->cart_items as $cartitem) { // exit('<pre>'.print_r($cartitem, true).'</pre>'); $categoriesIDs = $wpdb->get_col("SELECT category_id FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE product_id=" . $cartitem->product_id); foreach ((array) $categoriesIDs as $catid) { if (is_array($catid)) { $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid[0]; } else { $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid; } $countries = $wpdb->get_col($sql); if (in_array($selectedCountry[0]['id'], (array) $countries)) { $errormessage = sprintf(__('Oops the product : %s cannot be shipped to %s. To continue with your transaction please remove this product from the list above.', 'wpsc'), $cartitem->product_name, $selectedCountry[0]['country']); $_SESSION['categoryAndShippingCountryConflict'] = $errormessage; $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } // exit('valid >'.$is_valid); if (array_search($submitted_gateway, $selected_gateways) !== false) { $_SESSION['wpsc_previous_selected_gateway'] = $submitted_gateway; } else { $is_valid = false; } if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '') { //exit('Not being called'); if ($num_items != $disregard_shipping) { //<-- new line of code $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed'); $is_valid = false; } } if ($is_valid == true || $_GET['gateway'] == 'noca') { $_SESSION['categoryAndShippingCountryConflict'] = ''; // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); $_SESSION['wpsc_sessionid'] = $sessionid; $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } $tax = $wpsc_cart->calculate_total_tax(); $total = $wpsc_cart->calculate_total_price(); // Make sure delivery and selected region are onlly saved if the country does have regions // Im unsure how this would effect countries that HAVE regions, i.e if you select Canada as country,, will your // region be alabama if no region was selected? $wpsc_cart->update_location(); if (!wpsc_has_regions($wpsc_cart->selected_country)) { $wpsc_cart->selected_region = ''; } if (!wpsc_has_regions($wpsc_cart->delivery_country)) { $wpsc_cart->delivery_region = ''; } $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` (`totalprice`,`statusno`, `sessionid`, `user_ID`, `date`, `gateway`, `billing_country`,`shipping_country`, `billing_region`, `shipping_region`, `base_shipping`,`shipping_method`, `shipping_option`, `plugin_version`, `discount_value`, `discount_data`,`find_us`) VALUES ('{$total}' ,'0', '{$sessionid}', '" . (int) $user_ID . "', UNIX_TIMESTAMP(), '{$submitted_gateway}', '{$wpsc_cart->selected_country}', '{$wpsc_cart->delivery_country}','{$wpsc_cart->selected_region}', '{$wpsc_cart->delivery_region}', '{$base_shipping}', '{$wpsc_cart->selected_shipping_method}', '{$wpsc_cart->selected_shipping_option}', '" . WPSC_VERSION . "', '{$wpsc_cart->coupons_amount}','{$wpsc_cart->coupons_name}', '{$find_us}')"; //exit($sql); $wpdb->query($sql); $purchase_log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('{$sessionid}') LIMIT 1"); //exit('PurchLog id'.$purchase_log_id); $wpsc_checkout->save_forms_to_db($purchase_log_id); $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (get_option('wpsc_also_bought') == 1) { wpsc_populate_also_bought_list(); } wp_get_current_user(); $our_user_id = $user_ID; do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id)); if (get_option('permalink_structure') != '') { $seperator = "?"; } else { $seperator = "&"; } if ($total <= 0) { $transaction_url_with_sessionid = add_query_arg('sessionid', $session_id, get_option('transact_url')); wp_redirect($transaction_url_with_sessionid); } /// submit to gateway $current_gateway_data =& $wpsc_gateways[$submitted_gateway]; if ($current_gateway_data['api_version'] >= 2.0) { $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id); $merchant_instance->construct_value_array(); $merchant_instance->submit(); //print_r($merchant_instance); } else { if ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') { $gateway_used = $current_gateway_data['internalname']; $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;"); $current_gateway_data['function']($seperator, $sessionid); //break; } else { if ($_POST['custom_gateway'] == 'google') { $gateway_used = $current_gateway_data['internalname']; $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;"); $_SESSION['gateway'] = 'google'; header('Location: ' . get_option('shopping_cart_url')); exit; //break; } } } if (isset($_GET['gateway']) && $_GET['gateway'] == 'noca') { //exit('HERE2'); echo transaction_results($sessionid, true); } else { //exit('HERE'); } } else { } }
function _wpsc_change_profile_country() { global $wpdb; $country_field_id = $_REQUEST['form_id']; $country = $_REQUEST['country']; $sql = $wpdb->prepare('SELECT unique_name FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE `id`= %d', $country_field_id); $country_field_unique_name = $wpdb->get_var($sql); $has_regions = wpsc_has_regions($country); $response = array('has_regions' => $has_regions); $region_unique_name = 'shippingstate'; if ($country_field_unique_name == 'billingcountry') { $region_unique_name = 'billingstate'; } $sql = $wpdb->prepare('SELECT id FROM ' . WPSC_TABLE_CHECKOUT_FORMS . ' WHERE unique_name=%s AND active="1"', $region_unique_name); $response['region_field_id'] = $wpdb->get_var($sql); if ($has_regions) { $response['html'] = "<select name='collected_data[" . $country_field_id . "][1]'>" . nzshpcrt_region_list($country, '') . "</select>"; } echo json_encode($response); exit; }
/** * form_field method, returns the form html * @access public */ function form_field() { global $wpdb, $user_ID; if ($user_ID > 0) { if (!isset($_SESSION['wpsc_checkout_saved_values'])) { $_SESSION['wpsc_checkout_saved_values'] = get_user_meta($user_ID, 'wpshpcrt_usr_profile', 1); } $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country'); $billing_country_id = wpsc_get_country_form_id_by_type('country'); } $saved_form_data = @htmlentities(stripslashes((string) $_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id]), ENT_QUOTES, 'UTF-8'); $an_array = ''; if (function_exists('wpsc_get_ticket_checkout_set')) { if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) { $an_array = '[]'; } } switch ($this->checkout_item->type) { case "address": case "delivery_address": case "textarea": $output = "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . $saved_form_data . "</textarea>"; break; case "checkbox": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { $i = mt_rand(); foreach ($options as $label => $value) { $output .= "<input type='hidden' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='-1' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/><input type='checkbox' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> "; $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>"; } } break; case "country": $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id()); break; case "delivery_country": if (wpsc_uses_shipping()) { $country_name = $wpdb->get_var("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $_SESSION['wpsc_delivery_country'] . "' LIMIT 1"); $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($_SESSION['wpsc_delivery_country']) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> "; } else { $checkoutfields = true; $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_delivery_country'], $_SESSION['wpsc_delivery_region'], $this->form_element_id(), $checkoutfields); } break; case "select": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>"; $output .= "<option value='-1'>Select an Option</option>"; foreach ((array) $options as $label => $value) { $value = esc_attr(str_replace(' ', '', $value)); $output .= "<option value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r"; } $output .= "</select>"; } break; case "radio": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { $i = mt_rand(); foreach ((array) $options as $label => $value) { $output .= "<input type='radio' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "'value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> "; $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>"; } } break; case "text": case "city": case "delivery_city": case "email": case "coupon": default: if ($this->checkout_item->unique_name == 'shippingstate') { if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_delivery_country'])) { $region_name = $wpdb->get_var("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`='" . $_SESSION['wpsc_delivery_region'] . "' LIMIT 1"); $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_region'] . "' size='4' /><span class='shipping_region_name'>" . $region_name . "</span> "; } else { $disabled = ''; if (wpsc_disregard_shipping_state_fields()) { $disabled = 'disabled = "disabled"'; } $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />"; } } elseif ($this->checkout_item->unique_name == 'billingstate') { if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_selected_country'])) { $output = ''; } else { $disabled = ''; if (wpsc_disregard_billing_state_fields()) { $disabled = 'disabled = "disabled"'; } $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />"; } } else { $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />"; } break; } return $output; }
/** * form_field method, returns the form html * @access public */ function form_field() { global $wpdb, $user_ID, $wpsc_customer_checkout_details; if ($user_ID > 0) { $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country'); $billing_country_id = wpsc_get_country_form_id_by_type('country'); } $saved_form_data = empty($wpsc_customer_checkout_details[$this->checkout_item->id]) ? null : $wpsc_customer_checkout_details[$this->checkout_item->id]; $an_array = ''; if (function_exists('wpsc_get_ticket_checkout_set')) { if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) { $an_array = '[]'; } } $output = ''; $delivery_country = wpsc_get_customer_meta('shipping_country'); $billing_country = wpsc_get_customer_meta('billing_country'); $delivery_region = wpsc_get_customer_meta('shipping_region'); $billing_region = wpsc_get_customer_meta('billing_region'); switch ($this->checkout_item->type) { case "address": case "delivery_address": case "textarea": $output .= "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . esc_html((string) $saved_form_data) . "</textarea>"; break; case "checkbox": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { $i = mt_rand(); foreach ($options as $label => $value) { ?> <label> <input <?php checked(in_array($value, (array) $saved_form_data)); ?> type="checkbox" name="collected_data[<?php echo esc_attr($this->checkout_item->id); ?> ]<?php echo $an_array; ?> []" value="<?php echo esc_attr($value); ?> " /> <?php echo esc_html($label); ?> </label> <?php } } break; case "country": $output = wpsc_country_region_list($this->checkout_item->id, false, $billing_country, $billing_region, $this->form_element_id()); break; case "delivery_country": if (wpsc_uses_shipping()) { $country_name = $wpdb->get_var($wpdb->prepare("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`= %s LIMIT 1", $delivery_country)); $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_country) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> "; } else { $checkoutfields = true; $output = wpsc_country_region_list($this->checkout_item->id, false, $delivery_country, $delivery_region, $this->form_element_id(), $checkoutfields); } break; case "select": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>"; $output .= "<option value='-1'>" . _x('Select an Option', 'Dropdown default when called within checkout class', 'wpsc') . "</option>"; foreach ((array) $options as $label => $value) { $value = esc_attr(str_replace(' ', '', $value)); $output .= "<option " . selected($value, $saved_form_data, false) . " value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r"; } $output .= "</select>"; } break; case "radio": $options = $this->get_checkout_options($this->checkout_item->id); if ($options != '') { foreach ((array) $options as $label => $value) { ?> <label> <input type="radio" <?php checked($value, $saved_form_data); ?> name="collected_data[<?php echo esc_attr($this->checkout_item->id); ?> ]<?php echo $an_array; ?> " value="<?php echo esc_attr($value); ?> " /> <?php echo esc_html($label); ?> </label> <?php } } break; case "text": case "city": case "delivery_city": case "email": case "coupon": default: if ($this->checkout_item->unique_name == 'shippingstate') { if (wpsc_uses_shipping() && wpsc_has_regions($delivery_country)) { $region_name = $wpdb->get_var($wpdb->prepare("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`= %d LIMIT 1", $delivery_region)); $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_region) . "' size='4' /><span class='shipping_region_name'>" . esc_html($region_name) . "</span> "; } else { $disabled = ''; if (wpsc_disregard_shipping_state_fields()) { $disabled = 'disabled = "disabled"'; } $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />"; } } elseif ($this->checkout_item->unique_name == 'billingstate') { $disabled = ''; if (wpsc_disregard_billing_state_fields()) { $disabled = 'disabled = "disabled"'; } $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />"; } else { $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />"; } break; } return $output; }
function wpsc_display_purchlog_shipping_state_and_postcode() { global $wpdb, $purchlogitem; $country = maybe_unserialize($purchlogitem->shippinginfo['shippingcountry']['value']); // exit('<pre>'.print_r($country,true).'</pre>'); $state = ''; if (wpsc_has_regions($country)) { if ($purchlogitem->shippinginfo['shippingstate']['value'] != '') { $state = $purchlogitem->shippingstate($purchlogitem->shippinginfo['shippingstate']['value']) . ', '; //exit('State: '.$state); } else { $country = maybe_unserialize($purchlogitem->shippinginfo['shippingcountry']['value']); if (is_array($country) && is_numeric($country[0])) { $state = $purchlogitem->shippingstate($country[0]) . ', '; $country = $country[1]; } else { $state = $purchlogitem->shippingstate($country[1]) . ', '; $country = $country[0]; } } } return $state . $purchlogitem->shippinginfo['shippingpostcode']['value']; //return $purchlogitem->shippinginfo['shippingstate']['value'].', '.$purchlogitem->shippinginfo['shippingpostcode']['value']; }
/** * Get the meta values from the contents of a meta value that mirrors what was once "checkout_details". * * @since 3.8.14 * @param string|int $id Customer ID. Optional. Defaults to current customer * @return array checkout details array */ function _wpsc_get_deprecated_visitor_meta_checkout_details($meta_value, $key = 'checkout_details', $id = null) { if (!$id) { $id = wpsc_get_current_customer_id(); } remove_filter('wpsc_get_visitor_meta_checkout_details', '_wpsc_get_deprecated_visitor_meta_checkout_details', 1, 3); global $wpdb; $form_sql = 'SELECT * FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE `active` = "1" ORDER BY `checkout_set`, `checkout_order`;'; $form_data = $wpdb->get_results($form_sql, ARRAY_A); $meta_data_in_old_format = array(); foreach ($form_data as $index => $form_field) { if (!empty($form_field['unique_name'])) { $meta_key = $form_field['unique_name']; $meta_value = wpsc_get_visitor_meta($id, $meta_key, true); switch ($form_field['type']) { case 'delivery_country': // if the meta value is an array, the country is the first element, region is the second if (is_array($meta_value)) { $country = $meta_value[0]; } else { $country = $meta_value; } if (wpsc_has_regions($country)) { $meta_value = array($meta_value, wpsc_get_customer_meta('shippingregion')); } $meta_data_in_old_format[$form_field['id']] = $meta_value; break; case 'country': // if the meta value is an array, the country is the first element, region is the second if (is_array($meta_value)) { $country = $meta_value[0]; } else { $country = $meta_value; } if (wpsc_has_regions($country)) { $meta_value = array(0 => $meta_value, wpsc_get_customer_meta('billingregion')); } $meta_data_in_old_format[$form_field['id']] = $meta_value; break; default: $meta_data_in_old_format[$form_field['id']] = $meta_value; break; } } } $deprecated_meta_value = wpsc_get_visitor_meta($id, $key, true); if (!empty($deprecated_meta_value)) { wpsc_delete_visitor_meta($id, $key); } add_filter('wpsc_get_visitor_meta_checkout_details', '_wpsc_get_deprecated_visitor_meta_checkout_details', 1, 3); return $meta_data_in_old_format; }