/** * On the checkout page create a hidden element holding the acceptable shipping countries * * This let's the wp-e-commerce javascript process any dependency rules even if the store has configured * the checkout forms so that some fields are hidden. The most important of these fields are the * country, region and state fields. But it's just as easy to include all of them and not worry about * what various parts of WPeC, themes or plugs may be doing. * * @since 3.8.14 * * @access private */ function _wpsc_acceptable_shipping_countries_into_checkout_page() { $acceptable_countries = wpsc_get_acceptable_countries(); // if the acceptable countries is true all available countries can be shipped to, // otherwise we are going to restrict the countries list if ($acceptable_countries !== true) { $country_code_list = array(); foreach ($acceptable_countries as $key => $country_id) { $wpsc_country = new WPSC_Country($country_id); $country_code_list[$wpsc_country->get_isocode()] = $wpsc_country->get_name(); } ?> <script type="text/javascript"> /* <![CDATA[ */ var wpsc_acceptable_shipping_countries = <?php echo json_encode($country_code_list); ?> ; /* ]]> */ </script> <?php } }
function wpsc_place_shopping_cart($content = '') { if (!in_the_loop()) { return $content; } if (preg_match("/\\[shoppingcart\\]/", $content)) { // BEGIN: compatibility fix for outdated theme files still relying on sessions $_SESSION['coupon_numbers'] = wpsc_get_customer_meta('coupon'); $_SESSION['wpsc_checkout_misc_error_messages'] = wpsc_get_customer_meta('checkout_misc_error_messages'); $_SESSION['categoryAndShippingCountryConflict'] = wpsc_get_customer_meta('category_shipping_conflict'); $_SESSION['shippingSameBilling'] = wpsc_get_customer_meta('shippingSameBilling'); $_SESSION['wpsc_checkout_user_error_messages'] = wpsc_get_customer_meta('registration_error_messages'); // END: compatibility fix $GLOBALS['nzshpcrt_activateshpcrt'] = true; if (!defined('DONOTCACHEPAGE')) { define('DONOTCACHEPAGE', true); } // call this function to detect conflicts when the cart page is first loaded, otherwise // any conflict messages will only be displayed on the next page load wpsc_get_acceptable_countries(); ob_start(); do_action('wpsc_before_shopping_cart_page'); include wpsc_get_template_file_path('wpsc-shopping_cart_page.php'); do_action('wpsc_after_shopping_cart_page'); $output = ob_get_contents(); ob_end_clean(); $output = str_replace('$', '\\$', $output); wpsc_delete_customer_meta('checkout_misc_error_messages'); wpsc_delete_customer_meta('category_shipping_conflict'); wpsc_delete_customer_meta('registration_error_messages'); wpsc_delete_customer_meta('checkout_error_messages'); wpsc_delete_customer_meta('gateway_error_messages'); return preg_replace("/(<p>)*\\[shoppingcart\\](<\\/p>)*/", $output, $content); } else { return $content; } }
function wpsc_shipping_country_list($shippingdetails = false) { global $wpsc_shipping_modules; $wpsc_checkout = new wpsc_checkout(); $wpsc_checkout->checkout_item = $shipping_country_checkout_item = $wpsc_checkout->get_checkout_item('shippingcountry'); $output = ''; if ($shipping_country_checkout_item && $shipping_country_checkout_item->active) { if (!$shippingdetails) { $output = "<input type='hidden' name='wpsc_ajax_action' value='update_location' />"; } $acceptable_countries = wpsc_get_acceptable_countries(); // if there is only one country to choose from we are going to set that as the shipping country, // later in the UI generation the same thing will happen to make the single country the current // selection $countries = WPSC_Countries::get_countries(false); if (count($countries) == 1) { reset($countries); $id_of_only_country_available = key($countries); $wpsc_country = new WPSC_Country($id_of_only_country_available); wpsc_update_customer_meta('shippingcountry', $wpsc_country->get_isocode()); } $selected_country = wpsc_get_customer_meta('shippingcountry'); $additional_attributes = 'data-wpsc-meta-key="shippingcountry" '; $output .= wpsc_get_country_dropdown(array('id' => 'current_country', 'name' => 'country', 'class' => 'current_country wpsc-visitor-meta', 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce'))); } $output .= wpsc_checkout_shipping_state_and_region(); $zipvalue = (string) wpsc_get_customer_meta('shippingpostcode'); $zip_code_text = __('Your Zipcode', 'wp-e-commerce'); if ($zipvalue != '' && $zipvalue != $zip_code_text) { $color = '#000'; wpsc_update_customer_meta('shipping_zip', $zipvalue); } else { $zipvalue = $zip_code_text; $color = '#999'; } $uses_zipcode = false; $custom_shipping = get_option('custom_shipping_options'); foreach ((array) $custom_shipping as $shipping) { if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) { $uses_zipcode = true; } } if ($uses_zipcode) { $output .= " <input data-wpsc-meta-key='shippingpostcode' class='wpsc-visitor-meta' type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>"; } return $output; }
function wpsc_shipping_country_list($shippingdetails = false) { global $wpdb, $wpsc_shipping_modules, $wpsc_country_data; $js = ''; $output = ''; if (!$shippingdetails) { $output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />"; $js = " onchange='submit_change_country();'"; } $selected_country = (string) wpsc_get_customer_meta('shipping_country'); $selected_region = (string) wpsc_get_customer_meta('shipping_region'); if (empty($selected_country)) { $selected_country = esc_attr(get_option('base_country')); } if (empty($selected_region)) { $selected_region = esc_attr(get_option('base_region')); } if (empty($wpsc_country_data)) { $country_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `visible`= '1' ORDER BY `country` ASC", ARRAY_A); } else { $country_data = $wpsc_country_data; } $acceptable_countries = wpsc_get_acceptable_countries(); $output .= wpsc_get_country_dropdown(array('name' => 'country', 'id' => 'current_country', 'additional_attributes' => $js, 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'placeholder' => '')); $output .= wpsc_shipping_region_list($selected_country, $selected_region, $shippingdetails); if (isset($_POST['wpsc_update_location']) && $_POST['wpsc_update_location'] == 'true') { wpsc_update_customer_meta('update_location', true); } else { wpsc_delete_customer_meta('update_location'); } $zipvalue = (string) wpsc_get_customer_meta('shipping_zip'); if (!empty($_POST['zipcode'])) { $zipvalue = $_POST['zipcode']; } $zip_code_text = __('Your Zipcode', 'wpsc'); if ($zipvalue != '' && $zipvalue != $zip_code_text) { $color = '#000'; wpsc_update_customer_meta('shipping_zip', $zipvalue); } else { $zipvalue = $zip_code_text; $color = '#999'; } $uses_zipcode = false; $custom_shipping = get_option('custom_shipping_options'); foreach ((array) $custom_shipping as $shipping) { if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) { $uses_zipcode = true; } } if ($uses_zipcode) { $output .= " <input type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>"; } return $output; }