本文整理汇总了PHP中WC_Geolocation类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Geolocation类的具体用法?PHP WC_Geolocation怎么用?PHP WC_Geolocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Geolocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: wskl_country_ip_block
public static function wskl_country_ip_block()
{
// 옵션을 업데이트할 때 발생하는 값을 체크하여,
// DB 덤프 등으로 옮겨 놓은 직후 임시 상태의 사이트에 대해서 IP 블록을 생략.
$target = wskl_get_option('ip_block_target');
if (site_url() != $target) {
return;
}
// result sample: array( 'country' => KR, 'state' => '' );
$result = WC_Geolocation::geolocate_ip($_SERVER['REMOTE_ADDR']);
$white_list = preg_replace('/\\s+/', '', get_option('wskl_white_ipcode_list'));
// not a valid white list. ip block will be disabled.
if (empty($white_list)) {
return;
}
// at least open for wp-login,
$white_list = explode(',', $white_list);
$allowed = FALSE;
foreach ($white_list as $country_code) {
if ($country_code == $result['country']) {
$allowed = TRUE;
break;
}
}
if (!$allowed) {
wp_die('Blocked by IP');
}
}
开发者ID:EricKim65,项目名称:woosym-korean-localization,代码行数:28,代码来源:class-wskl-ip-block.php
示例2: product_by_country
/**
* product_by_country.
*
* @version 2.5.0
* @since 2.5.0
*/
function product_by_country($visible, $product_id)
{
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
$country = isset($location['country']) ? $location['country'] : '';
$visible_countries = get_post_meta($product_id, '_' . 'wcj_product_by_country_visible', true);
if (is_array($visible_countries) && !in_array($country, $visible_countries)) {
return false;
}
return $visible;
}
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:21,代码来源:class-wcj-product-by-country.php
示例3: wcj_get_user_location
/**
* wcj_get_user_location.
*
* @version 2.5.0
*/
function wcj_get_user_location()
{
$country = '';
if (isset($_GET['country']) && '' != $_GET['country'] && wcj_is_user_role('administrator')) {
$country = $_GET['country'];
} else {
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
$country = isset($location['country']) ? $location['country'] : '';
}
return $country;
}
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:21,代码来源:class-wcj-shortcodes.php
示例4: get_database_info
/**
* Get array of database information. Version, prefix, and table existence.
*
* @return array
*/
public function get_database_info()
{
global $wpdb;
// WC Core tables to check existence of
$tables = apply_filters('woocommerce_database_tables', array('woocommerce_sessions', 'woocommerce_api_keys', 'woocommerce_attribute_taxonomies', 'woocommerce_downloadable_product_permissions', 'woocommerce_order_items', 'woocommerce_order_itemmeta', 'woocommerce_tax_rates', 'woocommerce_tax_rate_locations', 'woocommerce_shipping_zones', 'woocommerce_shipping_zone_locations', 'woocommerce_shipping_zone_methods', 'woocommerce_payment_tokens', 'woocommerce_payment_tokenmeta'));
if (get_option('db_version') < 34370) {
$tables[] = 'woocommerce_termmeta';
}
$table_exists = array();
foreach ($tables as $table) {
$table_exists[$table] = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s;", $wpdb->prefix . $table)) === $wpdb->prefix . $table;
}
// Return all database info. Described by JSON Schema.
return array('wc_database_version' => get_option('woocommerce_db_version'), 'database_prefix' => $wpdb->prefix, 'maxmind_geoip_database' => WC_Geolocation::get_local_database_path(), 'database_tables' => $table_exists);
}
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:20,代码来源:class-wc-rest-system-status-controller.php
示例5: create_order
/**
* Create an order. Error codes:
* 520 - Cannot insert order into the database.
* 521 - Cannot get order after creation.
* 522 - Cannot update order.
* 525 - Cannot create line item.
* 526 - Cannot create fee item.
* 527 - Cannot create shipping item.
* 528 - Cannot create tax item.
* 529 - Cannot create coupon item.
*
* @throws Exception
* @param $data Posted data.
* @return int|WP_ERROR
*/
public function create_order($data)
{
// Give plugins the opportunity to create an order themselves.
if ($order_id = apply_filters('woocommerce_create_order', null, $this)) {
return $order_id;
}
try {
$order_id = absint(WC()->session->get('order_awaiting_payment'));
$cart_hash = md5(json_encode(wc_clean(WC()->cart->get_cart_for_session())) . WC()->cart->total);
/**
* If there is an order pending payment, we can resume it here so
* long as it has not changed. If the order has changed, i.e.
* different items or cost, create a new order. We use a hash to
* detect changes which is based on cart items + order total.
*/
if ($order_id && ($order = wc_get_order($order_id)) && $order->has_cart_hash($cart_hash) && $order->has_status(array('pending', 'failed'))) {
// Action for 3rd parties.
do_action('woocommerce_resume_order', $order_id);
// Remove all items - we will re-add them later.
$order->remove_order_items();
} else {
$order = new WC_Order();
}
foreach ($data as $key => $value) {
if (is_callable(array($order, "set_{$key}"))) {
$order->{"set_{$key}"}($value);
}
}
$order->set_created_via('checkout');
$order->set_cart_hash($cart_hash);
$order->set_customer_id(apply_filters('woocommerce_checkout_customer_id', get_current_user_id()));
$order->set_currency(get_woocommerce_currency());
$order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
$order->set_customer_ip_address(WC_Geolocation::get_ip_address());
$order->set_customer_user_agent(wc_get_user_agent());
$order->set_customer_note(isset($data['order_comments']) ? $data['order_comments'] : '');
$order->set_payment_method($data['payment_method']);
$order->set_shipping_total(WC()->cart->shipping_total);
$order->set_discount_total(WC()->cart->get_cart_discount_total());
$order->set_discount_tax(WC()->cart->get_cart_discount_tax_total());
$order->set_cart_tax(WC()->cart->tax_total);
$order->set_shipping_tax(WC()->cart->shipping_tax_total);
$order->set_total(WC()->cart->total);
$this->create_order_line_items($order);
$this->create_order_fee_lines($order);
$this->create_order_shipping_lines($order);
$this->create_order_tax_lines($order);
$this->create_order_coupon_lines($order);
$order_id = $order->save();
// Let plugins add their own meta data.
do_action('woocommerce_checkout_update_order_meta', $order_id, $data);
return $order_id;
} catch (Exception $e) {
return new WP_Error('checkout-error', $e->getMessage());
}
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:71,代码来源:class-wc-checkout.php
示例6: wcj_validate_eu_vat_number
/**
* wcj_validate_eu_vat_number.
*/
function wcj_validate_eu_vat_number()
{
if (!isset($_GET['wcj_validate_eu_vat_number'])) {
return;
}
if (isset($_GET['wcj_eu_vat_number_to_check']) && '' != $_GET['wcj_eu_vat_number_to_check']) {
$eu_vat_number_to_check = substr($_GET['wcj_eu_vat_number_to_check'], 2);
$eu_vat_number_country_to_check = substr($_GET['wcj_eu_vat_number_to_check'], 0, 2);
if ('yes' === apply_filters('wcj_get_option_filter', 'no', get_option('wcj_eu_vat_number_check_ip_location_country', 'no'))) {
$location = WC_Geolocation::geolocate_ip();
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
$is_valid = $location['country'] === $eu_vat_number_country_to_check ? validate_VAT($eu_vat_number_country_to_check, $eu_vat_number_to_check) : false;
} else {
$is_valid = validate_VAT($eu_vat_number_country_to_check, $eu_vat_number_to_check);
}
} else {
$is_valid = null;
}
$_SESSION['wcj_is_eu_vat_number_valid'] = $is_valid;
$_SESSION['wcj_eu_vat_number_to_check'] = $_GET['wcj_eu_vat_number_to_check'];
echo $is_valid;
die;
}
开发者ID:yarwalker,项目名称:ecobyt,代码行数:28,代码来源:class-wcj-eu-vat-number.php
示例7: get_customer_country_group_id
/**
* get_customer_country_group_id.
*/
public function get_customer_country_group_id()
{
// We already know the group - nothing to calculate - return group
// if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 )
// return $this->customer_country_group_id;
// We've already tried - no country was detected, no need to try again
if (-1 === $this->customer_country_group_id) {
return null;
}
if (isset($_GET['country']) && '' != $_GET['country'] && is_super_admin()) {
$country = $_GET['country'];
} else {
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
$country = isset($location['country']) ? $location['country'] : null;
}
if (null === $country) {
$this->customer_country_group_id = -1;
return null;
}
// Get the country group id - go through all the groups, first found group is returned
for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_price_by_country_total_groups_number', 1)); $i++) {
$country_exchange_rate_group = get_option('wcj_price_by_country_exchange_rate_countries_group_' . $i);
$country_exchange_rate_group = str_replace(' ', '', $country_exchange_rate_group);
$country_exchange_rate_group = explode(',', $country_exchange_rate_group);
if (in_array($country, $country_exchange_rate_group)) {
$this->customer_country_group_id = $i;
//wcj_log( 'customer_country_group_id=' . $this->customer_country_group_id );
return $i;
}
}
// No country group found
$this->customer_country_group_id = -1;
return null;
}
开发者ID:sawan34,项目名称:tanzi,代码行数:42,代码来源:class-wcj-price-by-country-core.php
示例8: wc_get_customer_default_location
/**
* Get the customer's default location. Filtered, and set to base location or left blank.
*
* If cache-busting, this should only be used when 'location' is set in the querystring.
*
* @todo should the woocommerce_default_country option be renamed to contain 'base'?
* @since 2.3.0
* @return array
*/
function wc_get_customer_default_location()
{
switch (get_option('woocommerce_default_customer_address')) {
case 'geolocation_ajax':
case 'geolocation':
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
break;
case 'base':
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
break;
default:
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', ''));
break;
}
return $location;
}
开发者ID:slavic18,项目名称:cats,代码行数:29,代码来源:wc-core-functions.php
示例9: isset
$country_code = isset($data->country_code) ? $data->country_code : '';
break;
default:
$country_code = apply_filters('woocommerce_geolocation_geoip_response_' . $service_name, '', $response['body']);
break;
}
$country_code = sanitize_text_field(strtoupper($country_code));
if ($country_code) {
break;
}
}
}
set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS);
}
return $country_code;
}
/**
* Test if is IPv6
*
* @since 2.4.0
*
* @param string $ip_address
* @return bool
*/
private static function is_IPv6($ip_address)
{
return false !== filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
}
}
WC_Geolocation::init();
开发者ID:slavic18,项目名称:cats,代码行数:30,代码来源:class-wc-geolocation.php
示例10: delete_option
}
/* rename options regions */
delete_option('_oga_wppbc_countries_groups');
add_option('wc_price_based_country_regions', $regions);
/* sync variable products */
require_once WC()->plugin_path() . '/includes/class-wc-product-variable.php';
$rows = $wpdb->get_results($wpdb->prepare("SELECT distinct post_parent FROM {$wpdb->posts} where post_type = %s", 'product_variation'));
foreach ($rows as $row) {
WC_Product_Variable::sync($row->post_parent);
}
/* rename and update test options */
add_option('wc_price_based_country_test_mode', get_option('wc_price_based_country_debug_mode'));
delete_option('wc_price_based_country_debug_mode');
$test_ip = get_option('wc_price_based_country_debug_ip');
if ($test_ip) {
$country = WC_Geolocation::geolocate_ip($test_ip);
add_option('wc_price_based_country_test_country', $country['country']);
}
delete_option('wc_price_based_country_debug_ip');
/* unschedule geoip donwload */
if (wp_next_scheduled('wcpbc_update_geoip')) {
wp_clear_scheduled_hook('wcpbc_update_geoip');
}
delete_option('wc_price_based_country_update_geoip');
// Delete de options older options
delete_option('_oga_wppbc_apiurl');
delete_option('_oga_wppbc_api_country_field');
// Delete geoip db
$geoip_db_dir = wp_upload_dir();
$geoip_db_dir = $geoip_db_dir['basedir'] . '/wc_price_based_country';
if (file_exists($geoip_db_dir . '/GeoLite2-Country.mmdb')) {
开发者ID:raminabsari,项目名称:phonicsschool,代码行数:31,代码来源:wcpbc-update-1.3.2.php
示例11: get_debug_info
/**
* get_debug_info.
*
function get_debug_info( $args ) {
$html = '';
if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled' ) ) {
$html .= '<p>';
$html .= __( 'Price by Country on per Product Basis is enabled.', 'woocommerce-jetpack' );
$html .= '</p>';
}
$data = array();
$data[] = array( '#', __( 'Countries', 'woocommerce-jetpack' ), __( 'Focus Country', 'woocommerce-jetpack' ), __( 'Regular Price', 'woocommerce-jetpack' ), __( 'Sale Price', 'woocommerce-jetpack' ) );
global $product;
for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
$row = array();
$row[] = $i;
$country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
$country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
$row[] = $country_exchange_rate_group;
$country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
$_GET['country'] = $country_exchange_rate_group[0];
$row[] = $country_exchange_rate_group[0];
$currency_code = wcj_get_currency_symbol( get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i ) );
$row[] = $product->get_regular_price() . ' ' . $currency_code;
$row[] = $product->get_sale_price() . ' ' . $currency_code;
$data[] = $row;
}
//$html .= wcj_get_table_html( $data, '', false );
$html = wcj_get_table_html( $data, array( 'table_heading_type' => 'vertical', ) );
return $html;
}
/**
* fix_variable_product_price_on_sale.
*
public function fix_variable_product_price_on_sale( $price, $product ) {
if ( $product->is_type( 'variable' ) ) {
if ( ! $product->is_on_sale() ) {
$start_position = strpos( $price, '<del>' );
$length = strpos( $price, '</del>' ) - $start_position;
// Fixing the price, i.e. removing the sale tags
return substr_replace( $price, '', $start_position, $length );
}
}
// No changes
return $price;
}
/**
* get_customer_country_group_id.
*
* @version 2.2.6
*/
public function get_customer_country_group_id()
{
// We already know the group - nothing to calculate - return group
// if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 )
// return $this->customer_country_group_id;
// We've already tried - no country was detected, no need to try again
/* if ( -1 === $this->customer_country_group_id )
return null; */
if (isset($_GET['country']) && '' != $_GET['country'] && is_super_admin()) {
$country = $_GET['country'];
} elseif ('yes' === get_option('wcj_price_by_country_override_on_checkout_with_billing_country', 'no') && is_checkout() && '' != WC()->customer->get_country()) {
$country = WC()->customer->get_country();
} else {
if ('by_ip' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
$country = isset($location['country']) ? $location['country'] : null;
} elseif ('by_user_selection' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
/* $form_method = get_option( 'wcj_price_by_country_country_selection_box_method', 'get' );
if ( 'get' == $form_method ) {
$country = ( isset( $_GET[ 'wcj-country' ] ) ) ? $_GET[ 'wcj-country' ] : null;
} else {
$country = ( isset( $_POST[ 'wcj-country' ] ) ) ? $_POST[ 'wcj-country' ] : null;
} */
$country = isset($_SESSION['wcj-country']) ? $_SESSION['wcj-country'] : null;
} elseif ('by_wpml' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) {
$country = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : null;
}
}
if (null === $country) {
$this->customer_country_group_id = -1;
return null;
}
// Get the country group id - go through all the groups, first found group is returned
for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_price_by_country_total_groups_number', 1)); $i++) {
$country_exchange_rate_group = get_option('wcj_price_by_country_exchange_rate_countries_group_' . $i);
$country_exchange_rate_group = str_replace(' ', '', $country_exchange_rate_group);
//.........这里部分代码省略.........
开发者ID:yarwalker,项目名称:ecobyt,代码行数:101,代码来源:class-wcj-price-by-country-core.php
示例12: init_geo_currency
public function init_geo_currency()
{
$done = false;
if ($this->is_use_geo_rules()) {
$rules = $this->get_geo_rules();
$pd = WC_Geolocation::geolocate_ip();
$this->storage->set_val('woocs_user_country', $pd['country']);
$is_allowed = $this->is_first_unique_visit and function_exists('wc_clean') and function_exists('wp_validate_redirect');
if ($is_allowed) {
if (isset($pd['country']) and !empty($pd['country'])) {
if (!empty($rules)) {
foreach ($rules as $curr => $countries) {
if (!empty($countries) and is_array($countries)) {
foreach ($countries as $country) {
if ($country == $pd['country']) {
$this->storage->set_val('woocs_current_currency', $curr);
$this->current_currency = $curr;
$done = true;
break 2;
}
}
}
}
}
}
}
}
$this->storage->set_val('woocs_first_unique_visit', 1);
return $done;
}
开发者ID:websideas,项目名称:Mondova,代码行数:30,代码来源:index.php
示例13: get_user_ip
/**
* Get user's IP address
*/
public function get_user_ip()
{
return WC_Geolocation::get_ip_address();
}
开发者ID:jfitzsimmons,项目名称:soundtrackforspace,代码行数:7,代码来源:class-wc-gateway-paypal-pro.php
示例14: get_customer_country_by_ip
/**
* get_customer_country_by_ip.
*
* @version 2.5.1
* @since 2.5.0
*/
function get_customer_country_by_ip()
{
if (class_exists('WC_Geolocation')) {
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// Base fallback
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
return isset($location['country']) ? $location['country'] : null;
} else {
return null;
}
}
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:20,代码来源:class-wcj-price-by-country-core.php
示例15: init_geo_currency
private function init_geo_currency()
{
$done = false;
if ($this->is_use_geo_rules() and $this->is_first_unique_visit) {
$rules = $this->get_geo_rules();
$pd = WC_Geolocation::geolocate_ip();
if (isset($pd['country']) and !empty($pd['country'])) {
if (!empty($rules)) {
foreach ($rules as $curr => $countries) {
if (!empty($countries) and is_array($countries)) {
foreach ($countries as $country) {
if ($country == $pd['country']) {
$this->storage->set_val('woocs_current_currency', $curr);
$done = true;
break 2;
}
}
}
}
}
/*
* Array
(
[EUR] => Array
(
[0] => AF
)
[RUB] => Array
(
[0] => DZ
[1] => AZ
)
)
*/
}
}
return $done;
}
开发者ID:Inteleck,项目名称:hwc,代码行数:40,代码来源:index.php
示例16: test_get_system_status_info_database
/**
* Test to make sure database response is correct.
*
* @since 2.7.0
*/
public function test_get_system_status_info_database()
{
global $wpdb;
wp_set_current_user($this->user);
$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/system_status'));
$data = $response->get_data();
$database = $data['database'];
$this->assertEquals(get_option('woocommerce_db_version'), $database['wc_database_version']);
$this->assertEquals($wpdb->prefix, $database['database_prefix']);
$this->assertEquals(WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database']);
$this->assertArrayHasKey('woocommerce_payment_tokens', $database['database_tables']);
}
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:17,代码来源:system-status.php
示例17: create_order
/**
* Create an order. Error codes:
* 520 - Cannot insert order into the database.
* 521 - Cannot get order after creation.
* 522 - Cannot update order.
* 525 - Cannot create line item.
* 526 - Cannot create fee item.
* 527 - Cannot create shipping item.
* 528 - Cannot create tax item.
* 529 - Cannot create coupon item.
* @throws Exception
* @return int|WP_ERROR
*/
public function create_order()
{
global $wpdb;
// Give plugins the opportunity to create an order themselves
if ($order_id = apply_filters('woocommerce_create_order', null, $this)) {
return $order_id;
}
try {
// Start transaction if available
wc_transaction_query('start');
// Insert or update the post data
$order_id = absint(WC()->session->order_awaiting_payment);
$cart_hash = md5(json_encode(wc_clean(WC()->cart->get_cart_for_session())) . WC()->cart->total);
/**
* If there is an order pending payment, we can resume it here so
* long as it has not changed. If the order has changed, i.e.
* different items or cost, create a new order. We use a hash to
* detect changes which is based on cart items + order total.
*/
if ($order_id && ($order = wc_get_order($order_id)) && $order->has_cart_hash($cart_hash) && $order->has_status(array('pending', 'failed'))) {
// Action for 3rd parties.
do_action('woocommerce_resume_order', $order_id);
// Remove all items - we will re-add them later.
$order->remove_order_items();
/**
* Not resuming - lets create a new order object.
*/
} else {
$order = new WC_Order();
}
$order->set_created_via('checkout');
$order->set_cart_hash($cart_hash);
$order->set_customer_id($this->customer_id);
$order->set_currency(get_woocommerce_currency());
$order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
$order->set_customer_ip_address(WC_Geolocation::get_ip_address());
$order->set_customer_user_agent(wc_get_user_agent());
$order->set_customer_note(isset($this->posted['order_comments']) ? $this->posted['order_comments'] : '');
$order->set_payment_method($this->payment_method);
$order->set_shipping_total(WC()->cart->shipping_total);
$order->set_discount_total(WC()->cart->get_cart_discount_total());
$order->set_discount_tax(WC()->cart->get_cart_discount_tax_total());
$order->set_cart_tax(WC()->cart->tax_total);
$order->set_shipping_tax(WC()->cart->shipping_tax_total);
$order->set_total(WC()->cart->total);
// Billing and shipping addresses
if ($address_keys = array_merge(array_keys($this->checkout_fields['billing']), array_keys($this->checkout_fields['shipping']))) {
foreach ($address_keys as $key) {
if (is_callable(array($order, "set_{$key}"))) {
$order->{"set_{$key}"}($this->get_posted_address_data(str_replace(array('billing_', 'shipping_'), '', $key), strstr($key, 'billing_') ? 'billing' : 'shipping'));
}
}
}
// Add line items.
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$product = $values['data'];
$item = new WC_Order_Item_Product(array('quantity' => $values['quantity'], 'name' => $product ? $product->get_title() : '', 'tax_class' => $product ? $product->get_tax_class() : '', 'product_id' => $product && isset($product->id) ? $product->id : 0, 'variation_id' => $product && isset($product->variation_id) ? $product->variation_id : 0, 'variation' => $values['variation'], 'subtotal' => $values['line_subtotal'], 'total' => $values['line_total'], 'subtotal_tax' => $values['line_subtotal_tax'], 'total_tax' => $values['line_tax'], 'taxes' => $values['line_tax_data']));
$item->set_backorder_meta();
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_values = $values;
$item->legacy_cart_item_key = $cart_item_key;
$order->add_item($item);
}
// Add fees
foreach (WC()->cart->get_fees() as $fee_key => $fee) {
$item = new WC_Order_Item_Fee(array('name' => $fee->name, 'tax_class' => $fee->taxable ? $fee->tax_class : 0, 'total' => $fee->amount, 'total_tax' => $fee->tax, 'taxes' => array('total' => $fee->tax_data)));
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_fee = $fee;
$item->legacy_fee_key = $fee_key;
$order->add_item($item);
}
// Store shipping for all packages
foreach (WC()->shipping->get_packages() as $package_key => $package) {
if (isset($package['rates'][$this->shipping_methods[$package_key]])) {
$shipping_rate = $package['rates'][$this->shipping_methods[$package_key]];
$item = new WC_Order_Item_Shipping(array('method_title' => $shipping_rate->label, 'method_id' => $shipping_rate->id, 'total' => wc_format_decimal($shipping_rate->cost), 'taxes' => $shipping_rate->taxes, 'meta_data' => $shipping_rate->get_meta_data()));
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_package_key = $package_key;
$order->add_item($item);
}
}
// Store tax rows
foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
if ($tax_rate_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
$order->add_item(new WC_Order_Item_Tax(array('rate_id' => $tax_rate_id, 'tax_total' => WC()->cart->get_tax_amount($tax_rate_id), 'shipping_tax_total' => WC()->cart->get_shipping_tax_amount($tax_rate_id), 'rate_code' => WC_Tax::get_rate_code($tax_rate_id), 'label' => WC_Tax::get_rate_label($tax_rate_id), 'compound' => WC_Tax::is_compound($tax_rate_id))));
}
}
//.........这里部分代码省略.........
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:101,代码来源:class-wc-checkout.php
示例18: _e
if (in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation'))) {
?>
<tr>
<td data-export-label="MaxMind GeoIP Database"><?php
_e('MaxMind GeoIP Database', 'woocommerce');
?>
:</td>
<td class="help"><?php
echo wc_help_tip(__('The GeoIP database from MaxMind is used to geolocate customers.', 'woocommerce'));
?>
</td>
<td><?php
if (file_exists(WC_Geolocation::get_local_database_path())) {
echo '<mark class="yes"><span class="dashicons dashicons-yes"></span> <code class="private">' . esc_html(WC_Geolocation::get_local_database_path()) . '</code></mark> ';
} else {
printf('<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from %1$s to the path: %2$s. Scroll down to \\"Downloads\\" and download the \\"Binary / gzip\\" file next to \\"GeoLite Country\\"', 'woocommerce'), make_clickable('http://dev.maxmind.com/geoip/legacy/geolite/'), '<code class="private">' . WC_Geolocation::get_local_database_path() . '</code>') . '</mark>', WC_LOG_DIR);
}
?>
</td>
</tr>
<?php
}
?>
</tr>
</tbody>
</table>
<table class="wc_status_table widefat" cellspacing="0">
<thead>
<tr>
<th colspan="3" data-export-label="Active Plugins (<?php
echo count((array) get_option('active_plugins'));
开发者ID:Biont,项目名称:woocommerce,代码行数:31,代码来源:html-admin-page-status-report.php
示例19: wc_get_customer_default_location
/**
* Get the customer's default location.
*
* Filtered, and set to base location or left blank. If cache-busting,
* this should only be used when 'location' is set in the querystring.
*
* @todo should the woocommerce_default_country option be renamed to contain 'base'?
* @todo deprecate woocommerce_customer_default_location and support an array filter only to cover all cases.
* @since 2.3.0
* @return array
*/
function wc_get_customer_default_location()
{
$location = array();
switch (get_option('woocommerce_default_customer_address')) {
case 'geolocation_ajax':
case 'geolocation':
// Exclude common bots from geolocation by user agent.
$ua = wc_get_user_agent();
if (!strstr($ua, 'bot') && !strstr($ua, 'spider') && !strstr($ua, 'crawl')) {
$location = WC_Geolocation::geolocate_ip('', true, false);
}
// Base fallback.
if (empty($location['country'])) {
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
}
break;
case 'base':
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
break;
default:
$location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', ''));
break;
}
return apply_filters('woocommerce_customer_default_location_array', $location);
}
开发者ID:WPprodigy,项目名称:woocommerce,代码行数:36,代码来源:wc-core-functions.php
示例20: wc_setup_locale
/**
* Locale settings
*/
public function wc_setup_locale()
{
$user_location = WC_Geolocation::geolocate_ip();
$country = !empty($user_location['country']) ? $user_location['country'] : 'US';
$state = !empty($user_location['state']) ? $user_location['state'] : '*';
$state = 'US' === $country && '*' === $state ? 'AL' : $state;
// Defaults
$currency = get_option('woocommerce_currency', 'GBP');
$currency_pos = get_option('woocommerce_currency_pos', 'left');
$decimal_sep = get_option('woocommerce_decimal_sep', '.');
$thousand_sep = get_option('woocommerce_thousand_sep', ',');
$dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
$weight_unit = get_option('woocommerce_weight_unit', 'kg');
?>
<h1><?php
_e('Store Locale Setup', 'woocommerce');
?>
</h1>
<form method="post">
<table class="form-table">
<tr>
<th scope="row"><label for="store_location"><?php
_e('Where is your store based?', 'woocommerce');
?>
</label></th>
<td>
<select id="store_location" name="store_location" style="width:100%;" required data-placeholder="<?php
esc_attr_e('Choose a country…', 'woocommerce');
?>
" class="wc-enhanced-select">
<?php
WC()->countries->country_dropdown_options($country, $state);
?>
</select>
</td>
</tr>
<tr>
<th scope="row"><label for="currency_code"><?php
_e('Which currency will your store use?', 'woocommerce');
?>
</label></th>
<td>
<select id="currency_code" name="currency_code" required style="width:100%;" data-placeholder="<?php
esc_attr_e('Choose a currency…', 'woocommerce');
?>
" class="wc-enhanced-select">
<option value=""><?php
_e('Choose a currency…', 'woocommerce');
?>
</option>
<?php
foreach (get_woocommerce_currencies() as $code => $name) {
echo '<option value="' . esc_attr($code) . '" ' . checked($currency, $code, false) . '>' . esc_html($name . ' (' . get_woocommerce_currency_symbol($code) . ')') . '</option>';
}
?>
</select>
<span class="description"><?php
printf(__('If your currency is not listed you can %sadd it later%s.', 'woocommerce'), '<a href="http://docs.woothemes.com/document/add-a-custom-curr
|
请发表评论