/** * Get the country dropdown options, presumably for the checkout or customer profile pages * * @param string|array $args * * @return string HTML representation of the dropdown */ function _wpsc_country_dropdown_options($args = '') { $defaults = array('acceptable' => null, 'acceptable_ids' => null, 'selected' => '', 'disabled' => null, 'disabled_ids' => null, 'placeholder' => __('Please select a country', 'wpsc'), 'include_invisible' => false); $args = wp_parse_args($args, $defaults); $output = ''; $countries = WPSC_Countries::get_countries($args['include_invisible']); // if the user has a choice of countries the if (count($countries) > 1 && !empty($args['placeholder'])) { $output .= "<option value=''>" . esc_html($args['placeholder']) . "</option>\n\r"; } foreach ($countries as $country) { $isocode = $country->get_isocode(); $name = $country->get_name(); // if there is only one country in the list select it if (count($countries) == 1) { $args['selected'] = $isocode; } // if we're in admin area, and the legacy country code "UK" or "TP" is selected as the // base country, we should display both this and the more proper "GB" or "TL" options // and distinguish these choices somehow if (is_admin() && 11 > wpsc_core_get_db_version()) { if (in_array($isocode, array('TP', 'UK'))) { /* translators: This string will mark the legacy isocode "UK" and "TP" in the country selection dropdown as "legacy" */ $name = sprintf(__('%s (legacy)', 'wpsc'), $name); } elseif (in_array($isocode, array('GB', 'TL'))) { /* translators: This string will mark the legacy isocode "GB" and "TL" in the country selection dropdown as "ISO 3166" */ $name = sprintf(__('%s (ISO 3166)', 'wpsc'), $name); } } $output .= sprintf('<option value="%1$s" %2$s %3$s>%4$s</option>' . "\n\r", esc_attr($isocode), selected($args['selected'], $isocode, false), disabled(_wpsc_is_country_disabled($country, $args), true, false), esc_html($name)); } return $output; }
function get_local_currency_code() { if (empty($this->local_currency_code)) { $this->local_currency_code = WPSC_Countries::get_currency_code(get_option('currency_type')); } return $this->local_currency_code; }
/** * add countries data to the wpec javascript localizations * * @access private * @since 3.8.14 * * @param array localizations other localizations that can be added to * * @return array localizations array with countries information added */ function _wpsc_countries_localizations($localizations_array) { $localizations_array['no_country_selected'] = __('Please select a country', 'wpsc'); $localizations_array['no_region_selected_format'] = __('Please select a %s', 'wpsc'); $localizations_array['no_region_label'] = __('State/Province', 'wpsc'); $localizations_array['base_country'] = get_option('base_country'); $country_list = array(); foreach (WPSC_Countries::get_countries() as $country_id => $wpsc_country) { if ($wpsc_country->is_visible()) { $country_list[$wpsc_country->get_isocode()] = $wpsc_country->get_name(); if ($wpsc_country->has_regions()) { $regions = $wpsc_country->get_regions(); $region_list = array(); foreach ($regions as $region_id => $wpsc_region) { $region_list[$region_id] = $wpsc_region->get_name(); } if (!empty($region_list)) { $localizations_array['wpsc_country_' . $wpsc_country->get_isocode() . '_regions'] = $region_list; } } $region_label = $wpsc_country->get('region_label'); if (!empty($region_label)) { $localizations_array['wpsc_country_' . $wpsc_country->get_isocode() . '_region_label'] = $region_label; } } } if (!empty($country_list)) { $localizations_array['wpsc_countries'] = $country_list; } return $localizations_array; }
/** * Sets meta for countries that no longer exist in their former notation to be considered legacy. * * @access private * @since 3.8.14 */ function _wpsc_set_legacy_country_meta() { if ($wpsc_country = WPSC_Countries::get_country('YU')) { $wpsc_country->set('_is_country_legacy', true); } if ($wpsc_country = WPSC_Countries::get_country('AN')) { $wpsc_country->set('_is_country_legacy', true); } if ($wpsc_country = WPSC_Countries::get_country('TP')) { $wpsc_country->set('_is_country_legacy', true); } }
/** * Create a WPSC_Currency object * * @access public * * @since 3.8.14 * * @param string $code this currency's code, like "USD" for a U.S.A dollar, or "EUR" for a euro * @param string $symbol the text symbol for this currency, like "$" * @param string $symbol_html the HTML representation of the symbol, like "$" * @param string $name the currency name, like "US Dollar" or "Euro" * * @return void */ public function __construct($code, $symbol = null, $symbol_html = null, $name = null) { // if all parameters are specified we are trying to make a new currency object if (!empty($code) && ($symbol != null || $symbol_html != null || $name != null)) { // Create a new currency object $this->code = $code; $this->symbol = $symbol; $this->symbol_html = $symbol_html; $this->name = $name; } else { // if only code is specified the constructor is typing to get the information about an existing currency $wpsc_currency = WPSC_Countries::get_currency($code); $this->code = $wpsc_currency->code; $this->symbol = $wpsc_currency->symbol; $this->symbol_html = $wpsc_currency->symbol_html; $this->name = $wpsc_currency->name; } }
function nzshpcrt_region_list($selected_country = null, $selected_region = null) { global $wpdb; if ($selected_region == null) { $selected_region = get_option('base_region'); } $output = ""; $region_list = WPSC_Countries::get_regions($selected_country, true); if ($region_list != null) { foreach ($region_list as $region) { if ($selected_region == $region['id']) { $selected = "selected='selected'"; } else { $selected = ""; } $output .= "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>\r\n"; } } else { $output .= "<option value=''>" . esc_html__('None', 'wpsc') . "</option>\r\n"; } return $output; }
function wpsc_get_region($region_id) { $country_id = WPSC_Countries::get_country_id_by_region_id($region_id); $wpsc_region = new WPSC_Region($country_id, $region_id); return $wpsc_region->get_name(); }
/** * Save submitted options to the database. * @since 3.8.8 * @uses check_admin_referer() Prevents CSRF. * @uses update_option() Saves options to the database. * @uses wpdb::query() Queries the database. * @uses wpdb::get_col() Queries the database. * @access public */ private function save_options($selected = '') { global $wpdb, $wpsc_gateways; $updated = 0; //This is to change the Overall target market selection check_admin_referer('update-options', 'wpsc-update-options'); //Should be refactored along with the Marketing tab if (isset($_POST['change-settings'])) { if (isset($_POST['wpsc_also_bought']) && $_POST['wpsc_also_bought'] == 'on') { update_option('wpsc_also_bought', 1); } else { update_option('wpsc_also_bought', 0); } if (isset($_POST['display_find_us']) && $_POST['display_find_us'] == 'on') { update_option('display_find_us', 1); } else { update_option('display_find_us', 0); } if (isset($_POST['wpsc_share_this']) && $_POST['wpsc_share_this'] == 'on') { update_option('wpsc_share_this', 1); } else { update_option('wpsc_share_this', 0); } if (isset($_POST['wpsc_ga_disable_tracking']) && $_POST['wpsc_ga_disable_tracking'] == '1') { update_option('wpsc_ga_disable_tracking', 1); } else { update_option('wpsc_ga_disable_tracking', 0); } if (isset($_POST['wpsc_ga_currently_tracking']) && $_POST['wpsc_ga_currently_tracking'] == '1') { update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_currently_tracking', 0); } if (isset($_POST['wpsc_ga_advanced']) && $_POST['wpsc_ga_advanced'] == '1') { update_option('wpsc_ga_advanced', 1); update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_advanced', 0); } if (isset($_POST['wpsc_ga_tracking_id']) && !empty($_POST['wpsc_ga_tracking_id'])) { update_option('wpsc_ga_tracking_id', esc_attr($_POST['wpsc_ga_tracking_id'])); } else { update_option('wpsc_ga_tracking_id', ''); } } if (empty($_POST['countrylist2']) && !empty($_POST['wpsc_options']['currency_sign_location'])) { $selected = 'none'; } if (!isset($_POST['countrylist2'])) { $_POST['countrylist2'] = ''; } if (!isset($_POST['country_id'])) { $_POST['country_id'] = ''; } if (!isset($_POST['country_tax'])) { $_POST['country_tax'] = ''; } if ($_POST['countrylist2'] != null || !empty($selected)) { $AllSelected = false; if ($selected == 'all') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '1'"); $AllSelected = true; } if ($selected == 'none') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '0'"); $AllSelected = true; } if ($AllSelected != true) { $countrylist = $wpdb->get_col("SELECT id FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC "); //find the countries not selected $unselectedCountries = array_diff($countrylist, $_POST['countrylist2']); foreach ($unselectedCountries as $unselected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 0), array('id' => $unselected), '%d', '%d'); } //find the countries that are selected $selectedCountries = array_intersect($countrylist, $_POST['countrylist2']); foreach ($selectedCountries as $selected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 1), array('id' => $selected), '%d', '%d'); } } WPSC_Countries::clear_cache(); wpsc_core_flush_temporary_data(); } $previous_currency = get_option('currency_type'); //To update options if (isset($_POST['wpsc_options'])) { $_POST['wpsc_options'] = stripslashes_deep($_POST['wpsc_options']); // make sure stock keeping time is a number if (isset($_POST['wpsc_options']['wpsc_stock_keeping_time'])) { $skt = $_POST['wpsc_options']['wpsc_stock_keeping_time']; // I hate repeating myself $skt = (double) $skt; if ($skt <= 0 || $skt < 1 && $_POST['wpsc_options']['wpsc_stock_keeping_interval'] == 'hour') { unset($_POST['wpsc_options']['wpsc_stock_keeping_time']); unset($_POST['wpsc_options']['wpsc_stock_keeping_interval']); } } foreach ($_POST['wpsc_options'] as $key => $value) { if ($value != get_option($key)) { update_option($key, $value); $updated++; } } } if ($previous_currency != get_option('currency_type')) { $currency_code = $wpdb->get_var("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` IN ('" . absint(get_option('currency_type')) . "')"); $selected_gateways = get_option('custom_gateway_options'); $already_changed = array(); foreach ($selected_gateways as $selected_gateway) { if (isset($wpsc_gateways[$selected_gateway]['supported_currencies'])) { if (in_array($currency_code, $wpsc_gateways[$selected_gateway]['supported_currencies']['currency_list'])) { $option_name = $wpsc_gateways[$selected_gateway]['supported_currencies']['option_name']; if (!in_array($option_name, $already_changed)) { update_option($option_name, $currency_code); $already_changed[] = $option_name; } } } } } foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { if (is_object($shipping)) { $shipping->submit_form(); } } //This is for submitting shipping details to the shipping module if (!isset($_POST['update_gateways'])) { $_POST['update_gateways'] = ''; } if (!isset($_POST['custom_shipping_options'])) { $_POST['custom_shipping_options'] = null; } if ($_POST['update_gateways'] == 'true') { update_option('custom_shipping_options', $_POST['custom_shipping_options']); $shipadd = 0; foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { foreach ((array) $_POST['custom_shipping_options'] as $shippingoption) { if ($shipping->internal_name == $shippingoption) { $shipadd++; } } } } }
/** * wpsc_get_currency_code * * @param does not receive anything * @return returns the currency code used for the shop */ function wpsc_get_currency_code() { return WPSC_Countries::get_currency_code(get_option('currency_type')); }
function _wpsc_filter_control_select_country($output, $field, $args) { extract($field); $country_data = WPSC_Countries::get_countries(); $options = array(); foreach ($country_data as $country) { $isocode = $country->get_isocode(); $alternatives = array($country->get_isocode()); switch ($isocode) { case 'US': $alternatives[] = __('United States of America', 'wp-e-commerce'); break; case 'GB': $alternatives[] = __('Great Britain', 'wp-e-commerce'); $alternatives[] = __('England', 'wp-e-commerce'); $alternatives[] = __('Wales', 'wp-e-commerce'); $alternatives[] = __('UK', 'wp-e-commerce'); $alternatives[] = __('Scotland', 'wp-e-commerce'); $alternatives[] = __('Northern Ireland', 'wp-e-commerce'); break; } $alternatives = apply_filters('wpsc_country_alternative_spellings', $alternatives, $isocode, $country); $options[$country->get_isocode()] = array('title' => $country->get_name(), 'attributes' => array('data-alternative-spellings' => implode(' ', $alternatives))); } $output .= wpsc_form_select($name, $value, $options, array('id' => $id . '-control', 'class' => 'wpsc-form-select-country'), false); return $output; }
/** * get a country list for checkout * * @param string|null $form_id * @param deprecated|null $ajax * @param string|null $selected_country * @param deprecated|null $selected_region * @param string|null $supplied_form_id * @param boolean $shippingfields * @return string */ function wpsc_country_list($form_id = null, $ajax = null, $selected_country = null, $selected_region = null, $supplied_form_id = null, $shippingfields = false) { global $wpdb; $output = ''; if ($form_id != null) { $html_form_id = "region_country_form_{$form_id}"; } else { $html_form_id = 'region_country_form'; } if ($shippingfields) { $js = ''; $title = 'shippingcountry'; $id = 'shippingcountry'; } else { $js = ''; $title = 'billingcountry'; $id = 'billingcountry'; } if (empty($supplied_form_id)) { $supplied_form_id = $id; } // 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($id, $wpsc_country->get_isocode()); } $additional_attributes = 'data-wpsc-meta-key="' . $title . '" title="' . $title . '" ' . $js; $output .= "<div id='{$html_form_id}'>\n\r"; $output .= wpsc_get_country_dropdown(array('id' => $supplied_form_id, 'name' => "collected_data[{$form_id}][0]", 'class' => 'current_country wpsc-visitor-meta', 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce'))); $output .= "</div>\n\r"; return $output; }
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; }
public static function get_cache($value = null, $col = 'id') { $function = __CLASS__ . '::' . __FUNCTION__ . '()'; $replacement = 'WPSC_Countries::get_country()'; _wpsc_deprecated_function($function, '3.8.14', $replacement); if (defined('WPSC_LOAD_DEPRECATED') && WPSC_LOAD_DEPRECATED) { if (is_null($value) && $col == 'id') { $value = get_option('currency_type'); } // note that we can't store cache by currency code, the code is used by various countries // TODO: remove duplicate entry for Germany (Deutschland) if (!in_array($col, array('id', 'isocode'))) { return false; } return WPSC_Countries::get_country($value, WPSC_Countries::RETURN_AN_ARRAY); } }
function wpsc_donations($args = null) { global $wpdb; // Args not used yet but this is ready for when it is $args = wp_parse_args((array) $args, array()); $products = $wpdb->get_results("SELECT DISTINCT `p` . * , `m`.`meta_value` AS `special_price`\n\t\tFROM `" . $wpdb->postmeta . "` AS `m`\n\t\tJOIN `" . $wpdb->posts . "` AS `p` ON `m`.`post_id` = `p`.`ID`\n\t\tWHERE `p`.`post_parent` IN ('0')\n\t\t\tAND `m`.`meta_key` IN ('_wpsc_is_donation')\n\t\t\tAND `m`.`meta_value` IN( '1' )\n\t\tORDER BY RAND( )\n\t\tLIMIT 1", ARRAY_A); $output = ''; if ($products != null) { foreach ($products as $product) { $attached_images = (array) get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $product['ID'], 'orderby' => 'menu_order', 'order' => 'ASC')); $attached_image = $attached_images[0]; $output .= "<div class='wpsc_product_donation'>"; if ($attached_image->ID > 0) { $output .= "<img src='" . wpsc_product_image($attached_image->ID, get_option('product_image_width'), get_option('product_image_height')) . "' title='" . $product['post_title'] . "' alt='" . esc_attr($product['post_title']) . "' /><br />"; } // Get currency options $currency_sign_location = get_option('currency_sign_location'); $currency_type = get_option('currency_type'); WPSC_Countries::get_currency_symbol($currency_type); $price = get_post_meta($product['ID'], '_wpsc_price', true); // Output $output .= "<strong>" . $product['post_title'] . "</strong><br />"; $output .= $product['post_content'] . "<br />"; $output .= "<form class='product_form' name='donation_widget_" . $product['ID'] . "' method='post' action='' id='donation_widget_" . $product['ID'] . "'>"; $output .= "<input type='hidden' name='product_id' value='" . $product['ID'] . "'/>"; $output .= "<input type='hidden' name='item' value='" . $product['ID'] . "' />"; $output .= "<input type='hidden' name='wpsc_ajax_action' value='add_to_cart' />"; $output .= "<label for='donation_widget_price_" . $product['ID'] . "'>" . __('Donation', 'wp-e-commerce') . ":</label> {$currency_symbol}<input type='text' id='donation_widget_price_" . $product['ID'] . "' name='donation_price' value='" . esc_attr(number_format($price, 2)) . "' size='6' /><br />"; $output .= "<input type='submit' id='donation_widget_" . $product['ID'] . "_submit_button' name='Buy' class='wpsc_buy_button' value='" . __('Add To Cart', 'wp-e-commerce') . "' />"; $output .= "</form>"; $output .= "</div>"; } } else { $output = ''; } echo $output; }
public function set_customer_details() { $_POST['wpsc_checkout_details'] = array(); $_GET['amazon_reference_id'] = sanitize_text_field($_POST['amazon_reference_id']); try { if (!$this->reference_id) { throw new Exception(__('An Amazon payment method was not chosen.', 'wpsc')); } if (is_null($this->purchase_log)) { $log = _wpsc_get_current_controller()->get_purchase_log(); wpsc_update_customer_meta('current_purchase_log_id', $log->get('id')); $this->set_purchase_log($log); } global $wpsc_cart; // Update order reference with amounts $response = $this->api_request(array('Action' => 'SetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id, 'OrderReferenceAttributes.OrderTotal.Amount' => $wpsc_cart->calculate_total_price(), 'OrderReferenceAttributes.OrderTotal.CurrencyCode' => strtoupper($this->get_currency_code()), 'OrderReferenceAttributes.SellerNote' => sprintf(__('Order %s from %s.', 'wpsc'), $this->purchase_log->get('id'), urlencode(remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)))), 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => $this->purchase_log->get('id'), 'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'OrderReferenceAttributes.PlatformId' => 'A2Z8DY3R4G08IM')); if (is_wp_error($response)) { throw new Exception($response->get_error_message()); } if (isset($response['Error']['Message'])) { throw new Exception($response['Error']['Message']); } $response = $this->api_request(array('Action' => 'GetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id)); if (is_wp_error($response)) { throw new Exception($response->get_error_message()); } if (!isset($response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'])) { return; } $address = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination']; remove_action('wpsc_checkout_get_fields', '__return_empty_array'); add_filter('wpsc_validate_form', '__return_true'); $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); foreach ($fields as $field) { switch ($field->unique_name) { case 'shippingstate': $_POST['wpsc_checkout_details'][$field->id] = WPSC_Countries::get_region_id($address['CountryCode'], $address['StateOrRegion']); break; case 'shippingcountry': $_POST['wpsc_checkout_details'][$field->id] = $address['CountryCode']; break; case 'shippingpostcode': $_POST['wpsc_checkout_details'][$field->id] = $address['PostalCode']; break; case 'shippingcity': $_POST['wpsc_checkout_details'][$field->id] = $address['City']; break; } } } catch (Exception $e) { WPSC_Message_Collection::get_instance()->add($e->getMessage(), 'error', 'main', 'flash'); return; } }
/** * wpsc_change_tax function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_change_tax() { global $wpdb, $wpsc_cart; $form_id = absint($_POST['form_id']); $wpsc_selected_country = $wpsc_cart->selected_country; $wpsc_selected_region = $wpsc_cart->selected_region; $wpsc_delivery_country = $wpsc_cart->delivery_country; $wpsc_delivery_region = $wpsc_cart->delivery_region; $previous_country = wpsc_get_customer_meta('billingcountry'); global $wpdb, $user_ID, $wpsc_customer_checkout_details; if (isset($_POST['billing_country'])) { $wpsc_selected_country = $_POST['billing_country']; wpsc_update_customer_meta('billingcountry', $wpsc_selected_country); } if (isset($_POST['billing_region'])) { $wpsc_selected_region = absint($_POST['billing_region']); wpsc_update_customer_meta('billingregion', $wpsc_selected_region); } $check_country_code = WPSC_Countries::country_id(wpsc_get_customer_meta('billing_region')); if (wpsc_get_customer_meta('billingcountry') != $check_country_code) { $wpsc_selected_region = null; } if (isset($_POST['shipping_country'])) { $wpsc_delivery_country = $_POST['shipping_country']; wpsc_update_customer_meta('shippingcountry', $wpsc_delivery_country); } if (isset($_POST['shipping_region'])) { $wpsc_delivery_region = absint($_POST['shipping_region']); wpsc_update_customer_meta('shippingregion', $wpsc_delivery_region); } $check_country_code = WPSC_Countries::country_id($wpsc_delivery_region); if ($wpsc_delivery_country != $check_country_code) { $wpsc_delivery_region = null; } $wpsc_cart->update_location(); $wpsc_cart->get_shipping_method(); $wpsc_cart->get_shipping_option(); if ($wpsc_cart->selected_shipping_method != '') { $wpsc_cart->update_shipping($wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option); } $tax = $wpsc_cart->calculate_total_tax(); $total = wpsc_cart_total(); $total_input = wpsc_cart_total(false); if ($wpsc_cart->coupons_amount >= $total_input && !empty($wpsc_cart->coupons_amount)) { $total = 0; } if ($wpsc_cart->total_price < 0) { $wpsc_cart->coupons_amount += $wpsc_cart->total_price; $wpsc_cart->total_price = null; $wpsc_cart->calculate_total_price(); } $delivery_country = wpsc_get_customer_meta('shipping_country'); $output = _wpsc_ajax_get_cart(false); $output = $output['widget_output']; $json_response = array(); global $wpsc_checkout; if (empty($wpsc_checkout)) { $wpsc_checkout = new wpsc_checkout(); } $json_response['delivery_country'] = esc_js($delivery_country); $json_response['billing_country'] = esc_js($wpsc_selected_country); $json_response['widget_output'] = $output; $json_response['shipping_keys'] = array(); $json_response['cart_shipping'] = wpsc_cart_shipping(); $json_response['form_id'] = $form_id; $json_response['tax'] = $tax; $json_response['display_tax'] = wpsc_cart_tax(); $json_response['total'] = $total; $json_response['total_input'] = $total_input; $json_response['lock_tax'] = get_option('lock_tax'); $json_response['country_name'] = wpsc_get_country($delivery_country); if ('US' == $delivery_country || 'CA' == $delivery_country) { $output = wpsc_shipping_region_list($delivery_country, wpsc_get_customer_meta('shipping_region')); $output = str_replace(array("\n", "\r"), '', $output); $json_response['shipping_region_list'] = $output; } foreach ($wpsc_cart->cart_items as $key => $cart_item) { $json_response['shipping_keys'][$key] = wpsc_currency_display($cart_item->shipping); } $form_selected_country = null; $form_selected_region = null; $onchange_function = null; if (!empty($_POST['billing_country']) && $_POST['billing_country'] != 'undefined' && !isset($_POST['shipping_country'])) { $form_selected_country = $wpsc_selected_country; $form_selected_region = $wpsc_selected_region; $onchange_function = 'set_billing_country'; } else { if (!empty($_POST['shipping_country']) && $_POST['shipping_country'] != 'undefined' && !isset($_POST['billing_country'])) { $form_selected_country = $wpsc_delivery_country; $form_selected_region = $wpsc_delivery_region; $onchange_function = 'set_shipping_country'; } } if ($form_selected_country != null && $onchange_function != null) { $checkoutfields = 'set_shipping_country' == $onchange_function; $region_list = wpsc_country_region_list($form_id, false, $form_selected_country, $form_selected_region, $form_id, $checkoutfields); if ($region_list != null) { $json_response['region_list'] = str_replace(array("\n", "\r"), '', $region_list); } } echo json_encode($json_response); exit; }
/** * callback that creates / re-creates the data map mapping all active country ids to all active countries * * @access private * @since 3.8.14 * * @param WPSC_Data_Map $data_map Data map object being intitilized */ public static function _create_active_countries_map($data_map) { global $wpdb; // there are also invisible countries $sql = 'SELECT ' . ' id, country, isocode, currency, symbol, symbol_html, code, has_regions, tax, continent, visible ' . ' FROM `' . WPSC_TABLE_CURRENCY_LIST . '` WHERE `visible`= "1" ' . ' ORDER BY id ASC'; $countries_array = $wpdb->get_results($sql, OBJECT_K); // build an array to map from iso code to country, while we do this get any region data for the country foreach ($countries_array as $country_id => $country) { // create a new empty country object, add the properties we know about, then we add our region info $wpsc_country = new WPSC_Country(null); $wpsc_country->_copy_properties_from_stdclass($country); if ($country->has_regions) { $sql = 'SELECT id, code, country_id, name, tax ' . ' FROM `' . WPSC_TABLE_REGION_TAX . '` ' . ' WHERE `country_id` = %d ' . ' ORDER BY code ASC '; // put the regions list into our country object $regions = $wpdb->get_results($wpdb->prepare($sql, $country_id), OBJECT_K); /* * any properties that came in as text that should be numbers or boolean * get adjusted here, we also build an array to map from region code to region id */ foreach ($regions as $region_id => $region) { $region->id = intval($region_id); $region->country_id = intval($region->country_id); $region->tax = floatval($region->tax); // create a new empty region object, then copy our region data into it. $wpsc_region = new WPSC_Region(null, null); $wpsc_region->_copy_properties_from_stdclass($region); $wpsc_country->_regions->map($region->id, $wpsc_region); $wpsc_country->_region_id_by_region_code->map($region->code, $region->id); $wpsc_country->_region_id_by_region_name->map(strtolower($region->name), $region->id); } } $data_map->map($country_id, $wpsc_country); } self::$_dirty = true; }
/** * @description: wpec_taxes_get_region_code_by_id - given an id this funciton will * return the region code. * @param: id - a region id * @return: int or false * */ function wpec_taxes_get_region_code_by_id($region) { $region_code = false; if (!empty($region)) { $country_id = WPSC_Countries::get_country_id_by_region_id($region); if ($country_id) { $wpsc_country = new WPSC_Country($country_id); } if (isset($wpsc_country)) { $wpsc_region = $wpsc_country->get_region($region); if ($wpsc_region) { $region_code = $wpsc_region->get_code(); } } } return $region_code; }
function wpsc_admin_category_forms_edit() { global $wpdb; $category_value_count = 0; $category_name = ''; $category = array(); $category_id = absint($_REQUEST["tag_ID"]); $category = get_term($category_id, 'wpsc_product_category', ARRAY_A); $category['nice-name'] = wpsc_get_categorymeta($category['term_id'], 'nice-name'); $category['description'] = wpsc_get_categorymeta($category['term_id'], 'description'); $category['image'] = wpsc_get_categorymeta($category['term_id'], 'image'); $category['fee'] = wpsc_get_categorymeta($category['term_id'], 'fee'); $category['active'] = wpsc_get_categorymeta($category['term_id'], 'active'); $category['order'] = wpsc_get_categorymeta($category['term_id'], 'order'); $category['display_type'] = wpsc_get_categorymeta($category['term_id'], 'display_type'); $category['image_height'] = wpsc_get_categorymeta($category['term_id'], 'image_height'); $category['image_width'] = wpsc_get_categorymeta($category['term_id'], 'image_width'); $category['use_additional_form_set'] = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); ?> <tr> <td colspan="2"> <h3><?php esc_html_e('Advanced Store Settings', 'wpsc'); ?> </h3> <h4><?php esc_html_e('Shortcodes and Template Tags', 'wpsc'); ?> </h4> <p class='description'><?php esc_html_e('These settings override the general presentation settings found in Settings > Store > Presentation.', 'wpsc'); ?> </p> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="display_type"><?php esc_html_e('Catalog View', 'wpsc'); ?> </label> </th> <td> <?php $display_type = isset($category['display_type']) ? $category['display_type'] : ''; ?> <select name='display_type'> <option value='default'<?php selected($display_type, 'default'); ?> ><?php esc_html_e('Default View', 'wpsc'); ?> </option> <option value='list'<?php disabled(_wpsc_is_display_type_supported('list'), false); selected($display_type, 'list'); ?> ><?php esc_html_e('List View', 'wpsc'); ?> </option> <option value='grid' <?php disabled(_wpsc_is_display_type_supported('grid'), false); selected($display_type, 'grid'); ?> ><?php esc_html_e('Grid View', 'wpsc'); ?> </option> </select><br /> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Category Image', 'wpsc'); ?> </label> </th> <td> <?php $category_image = wpsc_category_image($category['term_id']); if ($category_image) { echo '<p><img src=' . esc_url($category_image) . ' alt="' . esc_attr($category['name']) . '" title="' . esc_attr($category['name']) . '" class="wpsc_category_image" /></p>'; } ?> <input type='file' name='image' value='' /><br /> <label><input type='checkbox' name='deleteimage' class="wpsc_cat_box" value='1' /><?php esc_html_e('Delete Image', 'wpsc'); ?> </label><br/> <span class="description"><?php esc_html_e('You can set an image for the category here. If one exists, check the box to delete.', 'wpsc'); ?> </span> </td> </tr> <?php if (function_exists("getimagesize")) { ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Thumbnail Size', 'wpsc'); ?> </label> </th> <td> <fieldset class="wpsc-width-height-fields"> <legend class="screen-reader-text"><span><?php esc_html_e('Thumbnail Size', 'wpsc'); ?> </span></legend> <label for="image_width"><?php esc_html_e('Width', 'wpsc'); ?> </label> <input name="image_width" type="number" step="1" min="0" id="image_width" value="<?php if (isset($category['image_width'])) { echo esc_attr($category['image_width']); } ?> " class="small-text"> <label for="large_size_h"><?php esc_html_e('Height', 'wpsc'); ?> </label> <input name="image_height" type="number" step="1" min="0" id="image_height" value="<?php if (isset($category['image_height'])) { echo esc_attr($category['image_height']); } ?> " class="small-text"> </fieldset> </td> </tr> <?php } // 'getimagesize' condition ?> <tr> <td colspan="2"><h4><?php esc_html_e('Shortcodes and Template Tags', 'wpsc'); ?> </h4></td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Display Category Shortcode', 'wpsc'); ?> </label> </th> <td> <code>[wpsc_products category_url_name='<?php echo $category["slug"]; ?> ']</code><br /> <span class="description"><?php esc_html_e('Shortcodes are used to display a particular category or group within any WordPress page or post.', 'wpsc'); ?> </span> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Display Category Template Tag', 'wpsc'); ?> </label> </th> <td> <code><?php echo wpsc_display_products_page( array( 'category_url_name' => '<?php echo $category["slug"]; ?> ' ) ); ?></code><br /> <span class="description"><?php esc_html_e('Template tags are used to display a particular category or group within your theme / template.', 'wpsc'); ?> </span> </td> </tr> <!-- START OF TARGET MARKET SELECTION --> <tr> <td colspan="2"> <h4><?php esc_html_e('Target Market Restrictions', 'wpsc'); ?> </h4> </td> </tr> <?php $countrylist = WPSC_Countries::get_countries_array(true, true); $selectedCountries = wpsc_get_meta($category_id, 'target_market', 'wpsc_category'); ?> <tr> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Target Markets', 'wpsc'); ?> </label> </th> <td> <?php if (wpsc_is_suhosin_enabled()) { ?> <em><?php esc_html_e('The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature, then disable the suhosin extension. If you can not do this, you will need to contact your hosting provider.', 'wpsc'); ?> </em> <?php } else { ?> <span><?php esc_html_e('Select', 'wpsc'); ?> : <a href='' class='wpsc_select_all'><?php esc_html_e('All', 'wpsc'); ?> </a> <a href='' class='wpsc_select_none'><?php esc_html_e('None', 'wpsc'); ?> </a></span><br /> <div id='resizeable' class='ui-widget-content multiple-select'> <?php foreach ($countrylist as $country) { if (in_array($country['id'], (array) $selectedCountries)) { ?> <input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?> ' value='<?php echo $country['id']; ?> ' checked='<?php echo $country['visible']; ?> ' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } else { ?> <input type='checkbox' name='countrylist2[]' id='countrylist2-<?php echo $country['id']; ?> ' value='<?php echo $country['id']; ?> ' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } } ?> </div> <?php } ?> <br /> <span class="description"><?php esc_html_e('Select the markets you are selling this category to.', 'wpsc'); ?> </span> </td> </tr> <!-- Checkout settings --> <tr> <td colspan="2"> <h4><?php esc_html_e('Checkout Settings', 'wpsc'); ?> </h4> </td> </tr> <?php if (!isset($category['term_id'])) { $category['term_id'] = ''; } $used_additonal_form_set = wpsc_get_categorymeta($category['term_id'], 'use_additional_form_set'); $checkout_sets = get_option('wpsc_checkout_form_sets'); unset($checkout_sets[0]); $uses_billing_address = (bool) wpsc_get_categorymeta($category['term_id'], 'uses_billing_address'); ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="image"><?php esc_html_e('Category requires additional checkout form fields', 'wpsc'); ?> </label> </th> <td> <select name='use_additional_form_set'> <option value=''><?php esc_html_e('None', 'wpsc'); ?> </option> <?php foreach ((array) $checkout_sets as $key => $value) { $selected_state = ""; if ($used_additonal_form_set == $key) { $selected_state = "selected='selected'"; } ?> <option <?php echo $selected_state; ?> value='<?php echo $key; ?> '><?php echo esc_html($value); ?> </option> <?php } ?> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php esc_html_e('Address to calculate shipping with', 'wpsc'); ?> </label> </th> <td> <label><input type="radio" class="wpsc_cat_box" value="0" name="uses_billing_address" <?php echo $uses_billing_address != true ? 'checked="checked"' : ''; ?> /> <?php esc_html_e('Shipping Address (default)', 'wpsc'); ?> </label><br /> <label><input type="radio" class="wpsc_cat_box" value="1" name="uses_billing_address" <?php echo $uses_billing_address == true ? 'checked="checked"' : ''; ?> /> <?php esc_html_e('Billing Address', 'wpsc'); ?> </label> <p class='description'><?php esc_html_e('Products in this category will use the address specified to calculate shipping costs.', 'wpsc'); ?> </p> </td> </tr> <?php }
public function display() { global $wpdb; ?> <h3><?php echo esc_html_e('General Settings', 'wpsc'); ?> </h3> <table class='wpsc_options form-table'> <tr> <th scope="row"><label for="wpsc-base-country-drop-down"><?php esc_html_e('Base Country/Region', 'wpsc'); ?> </label></th> <td> <?php wpsc_country_dropdown(array('id' => 'wpsc-base-country-drop-down', 'name' => 'wpsc_options[base_country]', 'selected' => get_option('base_country'), 'include_invisible' => true)); ?> <span id='wpsc-base-region-drop-down'> <?php $this->display_region_drop_down(); ?> <img src="<?php echo esc_url(wpsc_get_ajax_spinner()); ?> " class="ajax-feedback" title="" alt="" /> </span> <p class='description'><?php esc_html_e('Select your primary business location.', 'wpsc'); ?> </p> </td> </tr> <?php /* START OF TARGET MARKET SELECTION */ $countrylist = WPSC_Countries::get_countries_array(true, true); ?> <tr> <th scope="row"> <?php esc_html_e('Target Markets', 'wpsc'); ?> </th> <td> <?php // check for the suhosin module if (wpsc_is_suhosin_enabled()) { echo "<em>" . __("The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpsc') . "</em>"; } else { ?> <span> <?php printf(__('Select: <a href="%1$s" class="wpsc-select-all" title="All">All</a> <a href="%2$s" class="wpsc-select-none" title="None">None</a>', 'wpsc'), esc_url(add_query_arg(array('selected_all' => 'all'))), esc_url(add_query_arg(array('selected_all' => 'none')))); ?> </span><br /> <div id='wpsc-target-markets' class='ui-widget-content multiple-select'> <?php foreach ((array) $countrylist as $country) { ?> <?php if ($country['visible'] == 1) { ?> <input type='checkbox' id="countrylist2-<?php echo $country['id']; ?> " name='countrylist2[]' value='<?php echo $country['id']; ?> ' checked='checked' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } else { ?> <input type='checkbox' id="countrylist2-<?php echo $country['id']; ?> " name='countrylist2[]' value='<?php echo $country['id']; ?> ' /> <label for="countrylist2-<?php echo $country['id']; ?> "><?php esc_html_e($country['country']); ?> </label><br /> <?php } ?> <?php } ?> </div> <p class='description'><?php esc_html_e('Select the markets you are selling products to.', 'wpsc'); ?> </p> <?php } ?> </td> </tr> <?php $stock_keeping_time = wpsc_get_stock_keeping_time(); $stock_keeping_interval = wpsc_get_stock_keeping_interval(); ?> <tr> <th scope="row"> <label for="wpsc-stock-keeping-time"><?php esc_html_e('Keep stock in cart for', 'wpsc'); ?> </label> </th> <td> <input type="text" name="wpsc_options[wpsc_stock_keeping_time]" id="wpsc-stock-keeping-time" size="2" value="<?php echo esc_attr($stock_keeping_time); ?> " /> <select name="wpsc_options[wpsc_stock_keeping_interval]"> <option value="hour" <?php selected('hour', $stock_keeping_interval); ?> ><?php echo _n('hour', 'hours', $stock_keeping_time, 'wpsc'); ?> </option> <option value="day" <?php selected('day', $stock_keeping_interval); ?> ><?php echo _n('day', 'days', $stock_keeping_time, 'wpsc'); ?> </option> <option value="week" <?php selected('week', $stock_keeping_interval); ?> ><?php echo _n('week', 'weeks', $stock_keeping_time, 'wpsc'); ?> </option> </select> <p class='description'><?php esc_html_e("Set the amount of time items in a customer's cart are reserved. You can also specify decimal amounts such as '0.5 days' or '1.25 weeks'. Note that the minimum interval you can enter is 1 hour, i.e. you can't schedule it to run every 0.5 hour.", 'wpsc'); ?> </p> </td> </tr> <?php $hierarchical_category = get_option('product_category_hierarchical_url', 0); ?> <tr> <th scope="row"> <?php _e('Use Hierarchical Product Category URL', 'wpsc'); ?> </th> <td> <label><input type="radio" <?php checked($hierarchical_category, 1); ?> name="wpsc_options[product_category_hierarchical_url]" value="1" /> <?php _e('Yes', 'wpsc'); ?> </label> <label><input type="radio" <?php checked($hierarchical_category, 0); ?> name="wpsc_options[product_category_hierarchical_url]" value="0" /> <?php _e('No', 'wpsc'); ?> </label><br /> <p class='description'><?php _e('When Hierarchical Product Category URL is enabled, parent product categories are also included in the product URL.<br />For example: <code>http://example.com/products-page/parent-cat/sub-cat/product-name</code>', 'wpsc'); ?> </p> </td> </tr> </table> <h3 class="form_group"><?php esc_html_e('Currency Settings', 'wpsc'); ?> </h3> <table class='wpsc_options form-table'> <?php $currency_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A); $currency_type = esc_attr(get_option('currency_type')); ?> <tr> <th scope="row"><label for="wpsc_options_currency_type"><?php esc_html_e('Currency Type', 'wpsc'); ?> </label></th> <td> <select id="wpsc_options_currency_type" name='wpsc_options[currency_type]' onchange='getcurrency(this.options[this.selectedIndex].value);'> <?php foreach ($currency_data as $currency) { ?> <option value='<?php echo $currency['id']; ?> ' <?php selected($currency['id'], $currency_type); ?> ><?php esc_html_e($currency['country']); ?> (<?php echo $currency['currency']; ?> )</option> <?php } ?> </select> </td> </tr> <?php $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . esc_attr(get_option('currency_type')) . "' LIMIT 1", ARRAY_A); if ($currency_data['symbol'] != '') { $currency_sign = esc_attr($currency_data['symbol_html']); } else { $currency_sign = esc_attr($currency_data['code']); } $currency_sign_location = esc_attr(get_option('currency_sign_location')); $csl1 = ""; $csl2 = ""; $csl3 = ""; $csl4 = ""; switch ($currency_sign_location) { case 1: $csl1 = "checked='checked'"; break; case 2: $csl2 = "checked='checked'"; break; case 3: $csl3 = "checked='checked'"; break; case 4: $csl4 = "checked='checked'"; break; } ?> <tr> <th scope="row"><?php esc_html_e('Currency Sign Location', 'wpsc'); ?> </th> <td> <input type='radio' value='1' name='wpsc_options[currency_sign_location]' id='csl1' <?php echo $csl1; ?> /> <label for='csl1'><?php _ex('100', 'Currency sign location - option 1', 'wpsc'); ?> <span id='cslchar1'><?php echo $currency_sign; ?> </span></label> <input type='radio' value='2' name='wpsc_options[currency_sign_location]' id='csl2' <?php echo $csl2; ?> /> <label for='csl2'><?php _ex('100', 'Currency sign location - option 2', 'wpsc'); ?> <span id='cslchar2'><?php echo $currency_sign; ?> </span></label> <input type='radio' value='3' name='wpsc_options[currency_sign_location]' id='csl3' <?php echo $csl3; ?> /> <label for='csl3'><span id='cslchar3'><?php echo $currency_sign; ?> </span><?php _ex('100', 'Currency sign location - option 3', 'wpsc'); ?> </label> <input type='radio' value='4' name='wpsc_options[currency_sign_location]' id='csl4' <?php echo $csl4; ?> /> <label for='csl4'><span id='cslchar4'><?php echo $currency_sign; ?> </span> <?php _ex('100', 'Currency sign location - option 4', 'wpsc'); ?> </label> </td> </tr> <tr> <th scope="row"><?php esc_html_e('Thousands and decimal separators', 'wpsc'); ?> </th> <td> <label for="wpsc_options_wpsc_thousands_separator"><?php esc_html_e('Thousands separator', 'wpsc'); ?> </label>: <input name="wpsc_options[wpsc_thousands_separator]" id="wpsc_options_wpsc_thousands_separator" type="text" maxlength="1" size="1" value="<?php echo esc_attr(get_option('wpsc_thousands_separator')); ?> " /><br /> <label for="wpsc_options_wpsc_decimal_separator"><?php esc_html_e('Decimal separator', 'wpsc'); ?> </label>: <input name="wpsc_options[wpsc_decimal_separator]" id="wpsc_options_wpsc_decimal_separator" type="text" maxlength="1" size="1" value="<?php echo esc_attr(get_option('wpsc_decimal_separator')); ?> " /><br /> <?php esc_html_e('Preview:', 'wpsc'); ?> 10<?php echo esc_attr(get_option('wpsc_thousands_separator')); ?> 000<?php echo esc_attr(get_option('wpsc_decimal_separator')); ?> 00 </td> </tr> </table> <?php }
function gateway_chronopay($separator, $sessionid) { global $wpdb; $purchase_log_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid); $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'"; $cart = $wpdb->get_results($cart_sql, ARRAY_A); // ChronoPay post variables $chronopay_url = get_option('chronopay_url'); $data['product_id'] = get_option('chronopay_product_id'); $data['product_name'] = get_option('chronopay_product_name'); $data['product_price_currency'] = get_option('chronopay_curcode'); $data['language'] = get_option('chronopay_language'); $data['cb_url'] = add_query_arg('chronopay_callback', 'true', home_url('/')); $data['cb_type'] = 'P'; $data['decline_url'] = home_url('/?chronopay_callback=true'); $data['cs1'] = $sessionid; $data['cs2'] = 'chronopay'; $salt = get_option('chronopay_salt'); $data['cs3'] = md5($salt . md5($sessionid . $salt)); // placed in here for security so that the return call can be validated as 'real' // User details if ($_POST['collected_data'][get_option('chronopay_form_first_name')] != '') { $data['f_name'] = $_POST['collected_data'][get_option('chronopay_form_first_name')]; } if ($_POST['collected_data'][get_option('chronopay_form_last_name')] != "") { $data['s_name'] = $_POST['collected_data'][get_option('chronopay_form_last_name')]; } if ($_POST['collected_data'][get_option('chronopay_form_address')] != '') { $data['street'] = str_replace("\n", ', ', $_POST['collected_data'][get_option('chronopay_form_address')]); } if ($_POST['collected_data'][get_option('chronopay_form_city')] != '') { $data['city'] = $_POST['collected_data'][get_option('chronopay_form_city')]; } $data['country'] = (string) wpsc_get_customer_meta('billingcountry'); // Change suggested by waxfeet@gmail.com, if email to be sent is not there, dont send an email address $email_data = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1'", ARRAY_A); foreach ((array) $email_data as $email) { $data['email'] = $_POST['collected_data'][$email['id']]; } if ($_POST['collected_data'][get_option('email_form_field')] != null && $data['email'] == null) { $data['email'] = $_POST['collected_data'][get_option('email_form_field')]; } // Get Currency details abd price $currency_code = WPSC_Countries::get_currency_code(get_option('currency_type')); $local_currency_code = $currency_code[0]['code']; $chronopay_currency_code = get_option('chronopay_curcode'); // ChronoPay only processes in the set currency. This is USD or EUR dependent on what the Chornopay account is set up with. // This must match the ChronoPay settings set up in wordpress. Convert to the chronopay currency and calculate total. $curr = new CURRENCYCONVERTER(); $decimal_places = 2; $total_price = 0; $i = 1; $all_donations = true; $all_no_shipping = true; foreach ($cart as $item) { $product_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->posts . "` WHERE `id`= %d LIMIT 1", $item['prodid']), ARRAY_A); $product_data = $product_data[0]; $variation_count = count($product_variations); //Does this even still work in 3.8? We're not using this table. $variation_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id` = %d", $item['id']); $variation_data = $wpdb->get_results($variation_sql, ARRAY_A); $variation_count = count($variation_data); if ($variation_count >= 1) { $variation_list = " ("; $j = 0; foreach ($variation_data as $variation) { if ($j > 0) { $variation_list .= ", "; } $value_id = $variation['venue_id']; $value_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`= %d LIMIT 1", $value_id), ARRAY_A); $variation_list .= $value_data[0]['name']; $j++; } $variation_list .= ")"; } else { $variation_list = ''; } $local_currency_productprice = $item['price']; $local_currency_shipping = $item['pnp']; $chronopay_currency_productprice = $local_currency_productprice; $chronopay_currency_shipping = $local_currency_shipping; $data['item_name_' . $i] = $product_data['name'] . $variation_list; $data['amount_' . $i] = number_format(sprintf("%01.2f", $chronopay_currency_productprice), $decimal_places, '.', ''); $data['quantity_' . $i] = $item['quantity']; $data['item_number_' . $i] = $product_data['id']; if ($item['donation'] != 1) { $all_donations = false; $data['shipping_' . $i] = number_format($chronopay_currency_shipping, $decimal_places, '.', ''); $data['shipping2_' . $i] = number_format($chronopay_currency_shipping, $decimal_places, '.', ''); } else { $data['shipping_' . $i] = number_format(0, $decimal_places, '.', ''); $data['shipping2_' . $i] = number_format(0, $decimal_places, '.', ''); } if ($product_data['no_shipping'] != 1) { $all_no_shipping = false; } $total_price = $total_price + $data['amount_' . $i] * $data['quantity_' . $i]; if ($all_no_shipping != false) { $total_price = $total_price + $data['shipping_' . $i] + $data['shipping2_' . $i]; } $i++; } $base_shipping = $purchase_log[0]['base_shipping']; if ($base_shipping > 0 && $all_donations == false && $all_no_shipping == false) { $data['handling_cart'] = number_format($base_shipping, $decimal_places, '.', ''); $total_price += number_format($base_shipping, $decimal_places, '.', ''); } $data['product_price'] = $total_price; // Create Form to post to ChronoPay $output = "\n\t\t<form id=\"chronopay_form\" name=\"chronopay_form\" method=\"post\" action=\"{$chronopay_url}\">\n"; foreach ($data as $n => $v) { $output .= "\t\t\t<input type=\"hidden\" name=\"{$n}\" value=\"{$v}\" />\n"; } $output .= "\t\t\t<input type=\"submit\" value=\"Continue to ChronoPay\" />\n\t\t</form>\n\t"; // Output the form. echo $output; echo "<script language=\"javascript\" type=\"text/javascript\">document.getElementById('chronopay_form').submit();</script>"; exit; }
function getQuote() { global $wpdb, $wpec_ash, $wpsc_cart, $wpec_ash_tools; // Arguments array for various functions to use $args = array(); $args['dest_ccode'] = wpsc_get_customer_meta('shippingcountry'); // Get the ups settings from the ups account info page (Shipping tab) $wpsc_ups_settings = get_option('wpsc_ups_settings', array()); //Disable International Shipping. Default: Enabled, as it currently is. $args['intl_rate'] = isset($wpsc_ups_settings['intl_rate']) && !empty($wpsc_ups_settings['intl_rate']) ? FALSE : TRUE; if (!$args['intl_rate'] && $args['dest_ccode'] != get_option('base_country')) { return array(); } // Destination zip code $args['dest_pcode'] = (string) wpsc_get_customer_meta('shippingpostcode'); if (!is_object($wpec_ash_tools)) { $wpec_ash_tools = new ASHTools(); } if (empty($args['dest_pcode']) && $wpec_ash_tools->needs_post_code($args['dest_ccode'])) { // We cannot get a quote without a zip code so might as well return! return array(); } // Get the total weight from the shopping cart $args['weight'] = wpsc_cart_weight_total(); if (empty($args['weight'])) { return array(); } $args['dest_state'] = ''; $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry')); if ($wpsc_country->has_regions()) { $wpsc_region = $wpsc_country->get_region(wpsc_get_customer_meta('shippingregion')); if (is_a($wpsc_region, 'WPSC_Region')) { $args['dest_state'] = $wpsc_region->get_code(); } } if (empty($args['dest_state'])) { $args['dest_state'] = wpsc_get_customer_meta('shippingstate'); } if (!is_object($wpec_ash)) { $wpec_ash = new ASH(); } $shipping_cache_check['state'] = $args['dest_state']; //The destination is needed for cached shipment check. $shipping_cache_check['country'] = $args['dest_ccode']; $shipping_cache_check['zipcode'] = $args['dest_pcode']; $this->shipment = $wpec_ash->get_shipment(); $this->shipment->set_destination($this->internal_name, $shipping_cache_check); //Set this shipment's destination. $this->shipment->rates_expire = date('Y-m-d'); $args['shipper'] = $this->internal_name; $args['singular_shipping'] = array_key_exists('singular_shipping', $wpsc_ups_settings) ? $wpsc_ups_settings['singular_shipping'] : '0'; if ($args['weight'] > 150 && !(bool) $args['singular_shipping']) { // This is where shipping breaks out of UPS if weight is higher than 150 LBS $over_weight_txt = apply_filters('wpsc_shipment_over_weight', __('Your order exceeds the standard shipping weight limit. Please contact us to quote other shipping alternatives.', 'wpsc'), $args); $shipping_quotes[$over_weight_txt] = 0; // yes, a constant. $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment); //Update shipment cache. return array($shipping_quotes); } $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment); //And now, we're ready to check cache. // We do not want to spam UPS (and slow down our process) if we already // have a shipping quote! if (count($cache['rate_table']) >= 1) { return $cache['rate_table']; } // Final rate table $rate_table = array(); // API Auth settings // $args['username'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsusername'] : ''; $args['password'] = array_key_exists('upspassword', $wpsc_ups_settings) ? $wpsc_ups_settings['upspassword'] : ''; $args['api_id'] = array_key_exists('upsid', $wpsc_ups_settings) ? $wpsc_ups_settings['upsid'] : ''; $args['account_number'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsaccount'] : ''; $args['negotiated_rates'] = array_key_exists('ups_negotiated_rates', $wpsc_ups_settings) ? $wpsc_ups_settings['ups_negotiated_rates'] : ''; $args['residential'] = $wpsc_ups_settings['49_residential']; $args['insured_shipment'] = array_key_exists('insured_shipment', $wpsc_ups_settings) ? $wpsc_ups_settings['insured_shipment'] : '0'; // What kind of pickup service do you use ? $args['DropoffType'] = $wpsc_ups_settings['DropoffType']; $args['packaging'] = $wpsc_ups_settings['48_container']; // Preferred Currency to display $currency_data = WPSC_Countries::get_currency_code(get_option('currency_type')); if (!empty($currency_data)) { $args['currency'] = $currency_data; } else { $args['currency'] = 'USD'; } // Shipping billing / account address $region = new WPSC_Region(get_option('base_country'), get_option('base_region')); $args['shipr_state'] = $region->get_code(); $args['shipr_city'] = get_option('base_city'); $args['shipr_ccode'] = get_option('base_country'); $args['shipr_pcode'] = get_option('base_zipcode'); // Physical Shipping address being shipped from $args['shipf_state'] = $args['shipr_state']; $args['shipf_city'] = $args['shipr_city']; $args['shipf_ccode'] = $args['shipr_ccode']; $args['shipf_pcode'] = $args['shipr_pcode']; $args['units'] = 'LBS'; $args['cart_total'] = $wpsc_cart->calculate_subtotal(true); $args = apply_filters('wpsc_shipment_data', $args, $this->shipment); if (isset($args['stop'])) { //Do not get rates. return array(); } // Build the XML request $request = $this->_buildRateRequest($args); // Now that we have the message to send ... Send it! $raw_quote = $this->_makeRateRequest($request); // Now we have the UPS response .. unfortunately its not ready // to be viewed by normal humans ... $quotes = $this->_parseQuote($raw_quote); // If we actually have rates back from UPS we can use em! if ($quotes != false) { $rate_table = apply_filters('wpsc_rates_table', $this->_formatTable($quotes, $args['currency']), $args, $this->shipment); } else { if (isset($wpsc_ups_settings['upsenvironment'])) { echo '<strong>:: GetQuote ::DEBUG OUTPUT::</strong><br />'; echo 'Arguments sent to UPS'; print_r($args); echo '<hr />'; print $request; echo '<hr />'; echo 'Response from UPS'; echo $raw_quote; echo '</strong>:: GetQuote ::End DEBUG OUTPUT::'; } } $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment); // return the final formatted array ! return $rate_table; }
public function display() { global $wpdb, $wpsc_shipping_modules, $external_shipping_modules, $internal_shipping_modules; // sort into external and internal arrays. foreach ($GLOBALS['wpsc_shipping_modules'] as $key => $module) { if (empty($module)) { continue; } if (isset($module->is_external) && $module->is_external) { $external_shipping_modules[$key] = $module; } else { $internal_shipping_modules[$key] = $module; } } ?> <h3><?php esc_html_e('Shipping Settings', 'wp-e-commerce'); ?> </h3> <input type='hidden' name='shipping_submits' value='true' /> <?php wp_nonce_field('update-options', 'wpsc-update-options'); ?> <input type='hidden' name='wpsc_admin_action' value='submit_options' /> <table class='form-table'> <?php /* wpsc_setting_page_update_notification displays the wordpress styled notifications */ wpsc_settings_page_update_notification(); ?> <tr> <th scope="row"><?php _e('Use Shipping', 'wp-e-commerce'); ?> </th> <td> <input type='hidden' value='1' name='wpsc_options[do_not_use_shipping]' /> <input type='checkbox' value='0' name='wpsc_options[do_not_use_shipping]' id='do_not_use_shipping' <?php checked('0', get_option('do_not_use_shipping')); ?> /> <label for='do_not_use_shipping'><?php _e('Enable Shipping settings', 'wp-e-commerce'); ?> </label> <p class='description'><?php esc_html_e('If you are only selling digital downloads, you should turn this off.', 'wp-e-commerce'); ?> </p> </td> </tr> <tr> <th><?php esc_html_e('Shipping Origin City', 'wp-e-commerce'); ?> </th> <td> <input type='text' name='wpsc_options[base_city]' value='<?php echo esc_attr(get_option('base_city')); ?> ' /> <p class='description'><?php esc_html_e('The name of the city where you fulfill and ship orders from. This enables us to give your customers more accurate shipping pricing.', 'wp-e-commerce'); ?> </p> </td> </tr> <tr> <th><?php esc_html_e('Shipping Origin Zipcode/Postcode', 'wp-e-commerce'); ?> </th> <td> <input type='text' name='wpsc_options[base_zipcode]' value='<?php echo esc_attr(get_option('base_zipcode')); ?> ' /> <p class='description'> <?php esc_html_e('The ZIP code / Postal code from where you fulfill and ship orders.', 'wp-e-commerce'); ?> <br /> <?php esc_html_e('If you are based in the United States, then this field is required in order for the UPS and USPS Shipping Calculators to work.', 'wp-e-commerce'); ?> </p> </td> </tr> <tr> <th scope="row"><?php _e('Shipwire', 'wp-e-commerce'); ?> <span style='color: red;'></span></th> <td> <input type='hidden' value='0' name='wpsc_options[shipwire]' /> <input type='checkbox' onclick='jQuery("#wpsc_shipwire_setting").toggle( jQuery(this).prop("checked") );' value='1' name='wpsc_options[shipwire]' id='shipwire' <?php checked('1', get_option('shipwire')); ?> /> <label for='shipwire'><?php _e('Enable Shipwire Integration', 'wp-e-commerce'); ?> </label> <p class='description'><?php printf(__('<a href="%1$s" target="_blank">Shipwire</a> provide e-commerce fulfillment warehouses. WP eCommerce can integrate stock inventory and shipping tracking with their service.', 'wp-e-commerce'), 'http://www.shipwire.com/pp/o.php?id=11922'); ?> </p> </td> </tr> <?php switch (get_option('shipwire')) { case 1: $shipwire_settings = ''; break; case 0: default: $shipwire_settings = 'style="display: none;"'; break; } ?> <tr id='wpsc_shipwire_setting' <?php echo $shipwire_settings; ?> > <th> </th> <td> <table> <tr> <th><?php esc_html_e('Shipwire Email', 'wp-e-commerce'); ?> </th> <td><input type="text" name='wpsc_options[shipwireemail]' value="<?php echo esc_attr(get_option('shipwireemail')); ?> " /></td> </tr> <tr> <th><?php esc_html_e('Shipwire Password', 'wp-e-commerce'); ?> </th> <td><input type="text" name='wpsc_options[shipwirepassword]' value="<?php echo esc_attr(get_option('shipwirepassword')); ?> " /></td> </tr> <tr> <th><?php esc_html_e('Use Test Server?', 'wp-e-commerce'); ?> </th> <td><input type="checkbox" name='wpsc_options[shipwire_test_server]' value="0" <?php checked('1', get_option('shipwire_test_server', '0')); ?> /></td> </tr> <tr> <th><?php esc_html_e('Force Sync with Shipwire', 'wp-e-commerce'); ?> </th> <td> <a class="shipwire_sync button"><?php esc_html_e('Update Tracking and Inventory', 'wp-e-commerce'); ?> </a> <img src="<?php echo esc_url(wpsc_get_ajax_spinner()); ?> " class="ajax-feedback" title="" alt="" /> </td> </tr> </table> </td> </tr> <?php $currency_data = WPSC_Countries::get_currency_data(get_option('currency_type'), true); if ($currency_data['symbol'] != '') { $currency_sign = $currency_data['symbol_html']; } else { $currency_sign = $currency_data['code']; } ?> <tr> <th><?php _e('Free Shipping Discount', 'wp-e-commerce'); ?> </th> <td> <?php if (get_option('shipping_discount') == 1) { $shipping_discount_settings = 'style=\'display: block;\''; } else { $shipping_discount_settings = ''; } ?> <input type='hidden' value='0' name='wpsc_options[shipping_discount]' /> <input type='checkbox' onclick='jQuery("#shipping_discount_value").toggle( jQuery(this).prop("checked") );' value='1' name='wpsc_options[shipping_discount]' id='shipping_discount' <?php checked('1', get_option('shipping_discount')); ?> /> <label for='shipping_discount'><?php _e('Enable Free Shipping Discount', 'wp-e-commerce'); ?> </label> </td> </tr> <tr> <td> </td> <td colspan="2"> <?php $value = wpsc_format_number(get_option('shipping_discount_value')); ?> <div <?php echo $shipping_discount_settings; ?> id='shipping_discount_value'> <?php printf(__('Sales over or equal to %1$s<input type="text" size="6" name="wpsc_options[shipping_discount_value]" value="%2$s" id="shipping_discount_value" /> will receive free shipping.', 'wp-e-commerce'), $currency_sign, esc_attr($value)); ?> </div> </td> </tr> </table> <?php submit_button(__('Save Changes', 'wp-e-commerce')); ?> <h3><?php _e('Shipping Modules', 'wp-e-commerce'); ?> </h3> <p class='description'><?php _e('To enable shipping in WP eCommerce you must select which shipping methods you want to enable on your site.', 'wp-e-commerce'); ?> </p> <p class='description'> <strong><?php _e('Tip', 'wp-e-commerce'); ?> </strong>: <?php printf(__('For fixed-price shipping options such as "Pickup - $0, Overnight - $10, Same day - $20, etc.", install our free <a href="%1$s">Fixed Rate Shipping</a> plugin.', 'wp-e-commerce'), 'http://wordpress.org/extend/plugins/wp-e-commerce-fixed-rate-shipping/'); ?> </p> <h4><?php _e('Internal Shipping Calculators', 'wp-e-commerce'); ?> </h4> <table id='wpsc-shipping-options-internal' class='wpsc-edit-module-options wp-list-table widefat plugins'> <thead> <tr> <th scope="col" id="wpsc-shipping-options-internal-active" class="manage-column"><?php _e('Active', 'wp-e-commerce'); ?> </th> <th scope="col" id="wpsc-shipping-options-internal-name" class="manage-column column-name"><?php _e('Shipping Calculator', 'wp-e-commerce'); ?> </th> </tr> </thead> <tfoot> <tr> <th scope="col" id="wpsc-shipping-options-internal-active" class="manage-column"><?php _e('Active', 'wp-e-commerce'); ?> </th> <th scope="col" id="wpsc-shipping-options-internal-name" class="manage-column column-name"><?php _e('Shipping Calculator', 'wp-e-commerce'); ?> </th> </tr> </tfoot> <tbody> <?php foreach ($internal_shipping_modules as $shipping) { $force = $shipping->getInternalName() === (string) get_user_option('wpsc_settings_selected_shipping_module', get_current_user_id()); $this->shipping_list_item($shipping, $force); } ?> </tbody> </table> <?php submit_button(__('Save Changes', 'wp-e-commerce')); ?> <h4><?php _e('External Shipping Calculators', 'wp-e-commerce'); ?> </h4> <?php if (!function_exists('curl_init')) { ?> <p style='color: red; font-size:8pt; line-height:10pt;'> <?php _e('The following shipping modules all need cURL which is not installed on this server. You may need to contact your web hosting provider to get it set up. ', 'wp-e-commerce'); ?> </p> <?php } ?> <table id='wpsc-shipping-options-external' class='wpsc-edit-module-options wp-list-table widefat plugins'> <thead> <tr> <th scope="col" id="wpsc-shipping-options-external-active" class="manage-column"><?php _e('Active', 'wp-e-commerce'); ?> </th> <th scope="col" id="wpsc-shipping-options-external-name" class="manage-column column-name"><?php _e('Shipping Calculator', 'wp-e-commerce'); ?> </th> </tr> </thead> <tfoot> <tr> <th scope="col" id="wpsc-shipping-options-external-active" class="manage-column"><?php _e('Active', 'wp-e-commerce'); ?> </th> <th scope="col" id="wpsc-shipping-options-external-name" class="manage-column column-name"><?php _e('Shipping Calculator', 'wp-e-commerce'); ?> </th> </tr> </tfoot> <tbody> <?php foreach ($external_shipping_modules as $shipping) { $force = $shipping->getInternalName() === (string) get_user_option('wpsc_settings_selected_shipping_module', get_current_user_id()); $this->shipping_list_item($shipping, $force); } ?> </tbody> </table> <?php }
/** * 3.4 */ public static function cryptocoin_payment($arr) { global $gourl, $wpdb; static $flag = false; if ($flag) { return false; } $flag = true; // Initialize // ------------------------ if (class_exists('gourlclass') && defined('GOURL') && is_object($gourl)) { $payments = $gourl->payments(); // Activated Payments $coin_names = $gourl->coin_names(); // All Coins $languages = $gourl->languages(); // All Languages } else { $payments = array(); $coin_names = array(); $languages = array(); } $statuses = array(2 => 'Order Received', 3 => 'Accepted Payment', 4 => 'Job Dispatched', 5 => 'Closed Order'); $mainplugin_url = admin_url("plugin-install.php?tab=search&type=term&s=GoUrl+Bitcoin+Payment+Gateway+Downloads"); $defcoin = get_option(GOURLWPSC . 'defcoin'); if (!in_array($defcoin, array_keys($payments))) { $defcoin = current(array_keys($payments)); } $deflang = get_option(GOURLWPSC . 'deflang'); if (!in_array($deflang, array_keys($languages))) { $deflang = current(array_keys($languages)); } $emultiplier = str_replace("%", "", get_option(GOURLWPSC . 'emultiplier')); if (!$emultiplier || !is_numeric($emultiplier) || $emultiplier <= 0) { $emultiplier = "1.00"; } $ostatus = get_option(GOURLWPSC . 'ostatus'); if (!in_array($ostatus, array_keys($statuses))) { $ostatus = 3; } // Accepted Payment $ostatus2 = get_option(GOURLWPSC . 'ostatus2'); if (!in_array($ostatus2, array_keys($statuses))) { $ostatus2 = 3; } // Accepted Payment $iconwidth = str_replace("px", "", get_option(GOURLWPSC . 'iconwidth')); if (!$iconwidth || !is_numeric($iconwidth) || $iconwidth < 30 || $iconwidth > 250) { $iconwidth = 60; } $iconwidth = $iconwidth . "px"; // Current Order // ----------------- $order_id = $arr["purchase_id"]; $order_total = $arr["purchase_log"]["totalprice"]; $order_currency = version_compare(WPSC_VERSION, '3.8.14', '<') ? current($wpdb->get_results("SELECT code FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE id = " . intval(get_option('currency_type')) . " LIMIT 1", ARRAY_A))["code"] : WPSC_Countries::get_currency_code(get_option('currency_type')); $order_user_id = $arr["purchase_log"]["user_ID"]; if ($order_currency == "DOG") { $order_currency = "DOGE"; } // WP eCommerce allow max 3 symbols for coin symbol if ($order_currency == "DAS") { $order_currency = "DASH"; } // WP eCommerce allow max 3 symbols for coin symbol // Security // ------------- if (!$order_id) { throw new Exception('The GoUrl payment plugin was called to process a payment but could not retrieve the order details for order_id. Cannot continue!'); } if ($arr["purchase_log"]["gateway"] != "wpsc_gourl_gateway" || $order_user_id && $order_user_id != get_current_user_id()) { return false; } if (!class_exists('gourlclass') || !defined('GOURL') || !is_object($gourl)) { echo '<h2>' . __('Information', GOURLWPSC) . '</h2>' . PHP_EOL; echo "<div style='border:1px solid #eee;margin:20px 10px;padding:10px'>" . __("Please try a different payment method. Admin need to install and activate wordpress plugin 'GoUrl Bitcoin Gateway' (https://gourl.io/bitcoin-wordpress-plugin.html) to accept Bitcoin/Altcoin Payments online", GOURLWPSC) . "</div>"; } elseif (!$payments || !$defcoin || true === version_compare(WPSC_VERSION, '3.8.10', '<') || true === version_compare(GOURL_VERSION, '1.3', '<') || array_key_exists($order_currency, $coin_names) && !array_key_exists($order_currency, $payments)) { echo '<h2>' . __('Information', GOURLWPSC) . '</h2>' . PHP_EOL; echo "<div style='border:1px solid #eee;margin:20px 10px;padding:10px'>" . sprintf(__('Sorry, but there was an error processing your order. Please try a different payment method or contact us if you need assistance. (GoUrl Bitcoin Plugin not configured - %s not activated)', GOURLWPSC), !$payments || !$defcoin ? "Cryptocurrency" : $coin_names[$order_currency]) . "</div>"; } else { $plugin = "gourlwpecommerce"; $amount = $order_total; $currency = $order_currency; $orderID = "order" . $order_id; $userID = $order_user_id; $period = "NOEXPIRY"; $language = $deflang; $coin = $coin_names[$defcoin]; $affiliate_key = "gourl"; $crypto = array_key_exists($currency, $coin_names); if (!$userID) { $userID = "guest"; } // allow guests to make checkout (payments) if (!$userID) { echo '<h2>' . __('Information', GOURLWPSC) . '</h2>' . PHP_EOL; echo "<div align='center'><a href='" . wp_login_url(get_permalink()) . "'>\n\t\t\t\t\t<img style='border:none;box-shadow:none;' title='" . __('You need first to login or register on the website to make Bitcoin/Altcoin Payments', GOURLWPSC) . "' vspace='10'\n\t\t\t\t\tsrc='" . $gourl->box_image() . "' border='0'></a></div>"; } elseif ($amount <= 0) { echo '<h2>' . __('Information', GOURLWPSC) . '</h2>' . PHP_EOL; echo "<div style='border:1px solid #eee;margin:20px 10px;padding:10px'>" . sprintf(__('This order’s amount is “%s” — it cannot be paid for. Please contact us if you need assistance.', GOURLWPSC), $amount . " " . $currency) . "</div>"; } else { // Exchange (optional) // -------------------- if ($currency != "USD" && !$crypto) { $amount = gourl_convert_currency($currency, "USD", $amount); if ($amount <= 0) { echo '<h2>' . __('Information', GOURLWPSC) . '</h2>' . PHP_EOL; echo "<div style='border:1px solid #eee;margin:20px 10px;padding:10px'>" . sprintf(__('Sorry, but there was an error processing your order. Please try later or use a different payment method. Cannot receive exchange rates for %s/USD from Google Finance', GOURLWPSC), $currency) . "</div>"; } else { $currency = "USD"; } } if (!$crypto) { $amount = $amount * $emultiplier; } // Payment Box // ------------------ if ($amount > 0) { // crypto payment gateway $result = $gourl->cryptopayments($plugin, $amount, $currency, $orderID, $period, $language, $coin, $affiliate_key, $userID, $iconwidth); if (!$result["is_paid"]) { echo '<h2>' . __('Pay Now', GOURLWPSC) . '</h2>' . PHP_EOL; } if ($result["error"]) { echo "<div style='border:1px solid #eee;margin:20px 10px;padding:10px'>" . __("Sorry, but there was an error processing your order. Please try a different payment method.", GOURLWPSC) . "<br/>" . $result["error"] . "</div>"; } else { // display payment box or successful payment result echo $result["html_payment_box"]; // payment received if ($result["is_paid"]) { echo "<div align='center'>" . sprintf(__('%s payment ID: #%s, order ID: #%s', GOURLWPSC), ucfirst($result["coinname"]), $result["paymentID"], $order_id) . "</div><br>"; } } } } } echo "<br><br>"; return true; }
/** * get_tax_rate method, gets the tax rate as a percentage, based on the selected country and region * * EDIT: Replaced with WPEC Taxes - this function should probably be deprecated * Note: to refresh cart items use wpsc_refresh_cart_items * * @access public */ function get_tax_rate() { $country = new WPSC_Country(get_option('base_country')); $country_data = WPSC_Countries::get_country(get_option('base_country'), true); $add_tax = false; if ($this->selected_country == get_option('base_country')) { // Tax rules for various countries go here, if your countries tax rules // deviate from this, please supply code to add your region switch ($this->selected_country) { case 'US': // USA! $tax_region = get_option('base_region'); if ($this->selected_region == get_option('base_region') && get_option('lock_tax_to_shipping') != '1') { // if they in the state, they pay tax $add_tax = true; } else { if ($this->delivery_region == get_option('base_region')) { // if they live outside the state, but are delivering to within the state, they pay tax also $add_tax = true; } } break; case 'CA': // Canada! apparently in canada, the region that you are in is used for tax purposes if ($this->selected_region != null) { $tax_region = $this->selected_region; } else { $tax_region = get_option('base_region'); } $add_tax = true; break; default: // Everywhere else! $tax_region = get_option('base_region'); if ($country->has_regions()) { if (get_option('base_region') == $region) { $add_tax = true; } } else { $add_tax = true; } break; } } if ($add_tax == true) { if ($country->has_regions()) { $region = $country->get_region($tax_region); $tax_percentage = $region->get_tax(); } else { $tax_percentage = $country->get_tax(); } } else { // no tax charged = tax equal to 0% $tax_percentage = 0; } if ($this->tax_percentage != $tax_percentage) { $this->clear_cache(); $this->tax_percentage = $tax_percentage; $this->wpsc_refresh_cart_items(); } }
/** * collate_data method, collate purchase data, like addresses, like country * @access public */ function collate_data() { global $wpdb; // Get purchase data, regardless of being fed the ID or the sessionid if ($this->purchase_id > 0) { $purchase_id =& $this->purchase_id; $purchase_logs = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = %d LIMIT 1", $purchase_id), ARRAY_A); } else { if ($this->session_id != null) { $purchase_logs = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = %s LIMIT 1", $this->session_id), ARRAY_A); $this->purchase_id = $purchase_logs['id']; $purchase_id =& $this->purchase_id; } } $email_address = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` AS `form_field` INNER JOIN `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` AS `collected_data` ON `form_field`.`id` = `collected_data`.`form_id` WHERE `form_field`.`type` IN ( 'email' ) AND `collected_data`.`log_id` IN ( '{$purchase_id}' )"); $currency_code = WPSC_Countries::get_currency_code(get_option('currency_type')); $collected_form_data = $wpdb->get_results("SELECT `data_names`.`id`, `data_names`.`unique_name`, `collected_data`.`value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` AS `collected_data` JOIN `" . WPSC_TABLE_CHECKOUT_FORMS . "` AS `data_names` ON `collected_data`.`form_id` = `data_names`.`id` WHERE `log_id` = '" . $purchase_id . "'", ARRAY_A); $address_data = array('billing' => array(), 'shipping' => array()); foreach ($collected_form_data as $collected_form_row) { $address_data_set = 'billing'; $address_key = array_search($collected_form_row['unique_name'], $this->address_keys['billing']); if ($address_key == null) { $address_data_set = 'shipping'; $address_key = array_search($collected_form_row['unique_name'], $this->address_keys['shipping']); } if ($address_key == null) { continue; } switch ($collected_form_row['unique_name']) { case 'billingcountry': case 'shippingcountry': $country = maybe_unserialize($collected_form_row['value']); if (is_array($country)) { $address_data[$address_data_set]['state'] = wpsc_get_state_by_id($country[1], 'code'); $country = $country[0]; } $address_data[$address_data_set][$address_key] = $country; break; case 'billingstate': case 'shippingstate': if (empty($address_data[$address_data_set]['state'])) { $address_data[$address_data_set]['state'] = is_numeric($collected_form_row['value']) ? wpsc_get_state_by_id($collected_form_row['value'], 'code') : $collected_form_row['value']; } break; default: $address_data[$address_data_set][$address_key] = $collected_form_row['value']; break; } } if (count($address_data['shipping']) < 1) { $address_data['shipping'] = $address_data['billing']; } if (!empty($purchase_logs['discount_value']) && $purchase_logs['discount_value'] > 0) { $has_discount = true; } else { $has_discount = false; } $this->cart_data = array('software_name' => 'WP eCommerce/' . WPSC_PRESENTABLE_VERSION . '', 'store_location' => get_option('base_country'), 'store_currency' => $currency_code, 'is_subscription' => false, 'has_discounts' => $has_discount, 'cart_discount_value' => $purchase_logs['discount_value'], 'cart_discount_coupon' => $purchase_logs['discount_data'], 'cart_tax' => $purchase_logs['wpec_taxes_total'], 'notification_url' => add_query_arg('wpsc_action', 'gateway_notification', home_url('/')), 'transaction_results_url' => get_option('transact_url'), 'shopping_cart_url' => get_option('shopping_cart_url'), 'products_page_url' => get_option('product_list_url'), 'base_shipping' => $purchase_logs['base_shipping'], 'total_price' => $purchase_logs['totalprice'], 'session_id' => $purchase_logs['sessionid'], 'transaction_id' => $purchase_logs['transactid'], 'email_address' => $email_address, 'billing_address' => $address_data['billing'], 'shipping_address' => $address_data['shipping']); }
/** * Cycles through the categories represented by the products in the cart. * Retrieves their target markets and returns an array of acceptable markets * We're only listing target markets that are acceptable for ALL categories in the cart * * @since 3.8.9 * @return array Countries that can be shipped to. If empty, sets session variable with appropriate error message */ function wpsc_get_acceptable_countries() { global $wpdb; $cart_category_ids = array_unique(wpsc_cart_item_categories(true)); $target_market_ids = array(); foreach ($cart_category_ids as $category_id) { $target_markets = wpsc_get_meta($category_id, 'target_market', 'wpsc_category'); if (!empty($target_markets)) { $target_market_ids[$category_id] = $target_markets; } } $have_target_market = !empty($target_market_ids); //If we're comparing multiple categories if (count($target_market_ids) > 1) { $target_market_ids = call_user_func_array('array_intersect', $target_market_ids); } elseif ($have_target_market) { $target_market_ids = array_values($target_market_ids); $target_market_ids = $target_market_ids[0]; } $country_data = WPSC_Countries::get_countries_array(); $have_target_market = $have_target_market && count($country_data) != count($target_market_ids); $GLOBALS['wpsc_country_data'] = $country_data; // TODO Is this ever used? $conflict_error = wpsc_get_customer_meta('category_shipping_conflict'); $target_conflict = wpsc_get_customer_meta('category_shipping_target_market_conflict'); // Return true if there are no restrictions if (!$have_target_market) { // clear out the target market messages if (!empty($target_conflict)) { wpsc_delete_customer_meta('category_shipping_conflict'); } wpsc_update_customer_meta('category_shipping_target_market_conflict', false); wpsc_update_customer_meta('category_shipping_conflict', false); return true; } // temporarily hijack this session variable to display target market restriction warnings if (!empty($target_conflict) || !wpsc_has_category_and_country_conflict()) { wpsc_update_customer_meta('category_shipping_target_market_conflict', true); wpsc_update_customer_meta('category_shipping_conflict', __("Some of your cart items are targeted specifically to certain markets. As a result, you can only select those countries as your shipping destination.", 'wp-e-commerce')); } if (empty($target_market_ids)) { wpsc_update_customer_meta('category_shipping_target_market_conflict', true); wpsc_update_customer_meta('category_shipping_conflict', __('It appears that some products in your cart have conflicting target market restrictions. As a result, there is no common destination country where your cart items can be shipped to. Please contact the site administrator for more information.', 'wp-e-commerce')); } return $target_market_ids; }
/** * saves region data to the database * * @access private * * @since 3.8.14 * * @param array key/value pairs that are put into the database columns * * @return int|boolean country_id on success, false on failure */ private function _save_region_data($region_data) { global $wpdb; /* * We need to figure out if we are updating an existing country. There are three * possible unique identifiers for a country. Look for a row that has any of the * identifiers. */ $region_id = isset($region_data['id']) ? intval($region_data['id']) : 0; $country_id = isset($region_data['country_id']) ? intval($region_data['country_id']) : 0; $region_code = isset($region_data['code']) ? $region_data['code'] : ''; $region_name = isset($region_data['code']) ? $region_data['code'] : ''; $region_id_from_db = false; /* * If at least one of the key feilds ins't present we aren'y going to continue, we can't reliably update * a row in the table, nor could we insrt a row that could reliably be updated. */ if (empty($country_id) || empty($region_code) || empty($region_name)) { _wpsc_doing_it_wrong(__FUNCTION__, __('Creating a new region requires country id, region code and region name.', 'wpsc'), '3.8.11'); return $region_id_from_db; } if ($region_id) { $sql = $wpdb->prepare('SELECT id FROM ' . WPSC_TABLE_REGION_TAX . ' WHERE (`id` = %d )', $region_id); $region_id_from_db = $wpdb->get_var($sql); } if (empty($region_id_from_db)) { // we are doing an insert of a new country $result = $wpdb->insert(WPSC_TABLE_REGION_TAX, $region_data); if ($result) { $region_id_from_db = $wpdb->insert_id; } } else { // we are doing an update of an existing country if (isset($region_data['id'])) { // no need to update the id to itself, don't want to allow changing of region id's either unset($region_data['id']); } $wpdb->update(WPSC_TABLE_REGION_TAX, $region_data, array('id' => $region_id_from_db), '%s', array('%d')); } // clear the cached data, force a rebuild WPSC_Countries::clear_cache(); return $region_id_from_db; }
/** * returns shipping quotes using this shipping module. * * @param boolean $for_display (optional) (unused) * @return array collection of rates applicable. */ function getQuote($for_display = false) { global $wpdb, $wpsc_cart; $quote_shipping_method = wpsc_get_customer_meta('quote_shipping_method'); $quote_shipping_option = wpsc_get_customer_meta('quote_shipping_option'); $country = ''; if (isset($_POST['country'])) { $country = sanitize_text_field($_POST['country']); wpsc_update_customer_meta('shipping_country', $country); } else { $country = (string) wpsc_get_customer_meta('shipping_country'); } if (is_object($wpsc_cart)) { $cart_total = $wpsc_cart->calculate_subtotal(true); } if (get_option('base_country') != $country) { $results = WPSC_Countries::get_continent($country); $flatrates = get_option('flat_rates'); if ($flatrates != '') { if ($quote_shipping_method == $this->internal_name && $quote_shipping_option != __("Flat Rate", 'wp-e-commerce')) { wpsc_delete_customer_meta('quote_shipping_option'); } if (isset($flatrates[$results])) { if (stristr($flatrates[$results], '%')) { $shipping_percent = str_replace('%', '', $flatrates[$results]); $shipping_amount = $cart_total * ($shipping_percent / 100); $flatrates[$results] = (double) $shipping_amount; } return array(__("Flat Rate", 'wp-e-commerce') => (double) $flatrates[$results]); } } } else { $flatrates = get_option('flat_rates'); $shipping_quotes = array(); switch ($country) { case 'NZ': if (isset($flatrates['northisland']) && strlen($flatrates['northisland']) > 0) { $shipping_quotes[__('North Island', 'wp-e-commerce')] = esc_attr($flatrates['northisland']); } if (isset($flatrates['southisland']) && strlen($flatrates['southisland']) > 0) { $shipping_quotes[__('South Island', 'wp-e-commerce')] = esc_attr($flatrates['southisland']); } break; case 'US': if (isset($flatrates['continental']) && strlen($flatrates['continental']) > 0) { $shipping_quotes[__('Continental 48 States', 'wp-e-commerce')] = esc_attr($flatrates['continental']); } if (isset($flatrates['all']) && strlen($flatrates['all']) > 0) { $shipping_quotes[__('All 50 States', 'wp-e-commerce')] = esc_attr($flatrates['all']); } break; default: if (isset($flatrates['local']) && strlen($flatrates['local']) > 0) { $shipping_quotes[__('Local Shipping', 'wp-e-commerce')] = esc_attr($flatrates['local']); } break; } // Deal with % shipping rates foreach (array_keys($shipping_quotes) as $quote_name) { if (stristr($shipping_quotes[$quote_name], '%')) { $shipping_percent = str_replace('%', '', $shipping_quotes[$quote_name]); $shipping_amount = $cart_total * ($shipping_percent / 100); $shipping_quotes[$quote_name] = (double) $shipping_amount; } else { $shipping_quotes[$quote_name] = (double) $shipping_quotes[$quote_name]; } } if ($quote_shipping_method == $this->internal_name) { $shipping_options = array_keys($shipping_quotes); if (array_search($quote_shipping_option, $shipping_options) === false) { wpsc_delete_customer_meta('quote_shipping_option'); } } return $shipping_quotes; } }
/** * wpsc_get_currency_symbol * @param does not receive anything * @return returns the currency symbol used for the shop */ function wpsc_get_currency_symbol() { $currency_type = get_option('currency_type'); $wpsc_currency_data = WPSC_Countries::get_currency_symbol($currency_type); return $wpsc_currency_data; }