当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Validation::is_phone方法代码示例

本文整理汇总了PHP中WC_Validation::is_phone方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Validation::is_phone方法的具体用法?PHP WC_Validation::is_phone怎么用?PHP WC_Validation::is_phone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Validation的用法示例。


在下文中一共展示了WC_Validation::is_phone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: data_provider_test_is_phone

 /**
  * Data provider for test_is_phone.
  *
  * @since 2.4
  */
 public function data_provider_test_is_phone()
 {
     return array(array(true, WC_Validation::is_phone('+00 000 00 00 000')), array(true, WC_Validation::is_phone('+00-000-00-00-000')), array(true, WC_Validation::is_phone('(000) 00 00 000')), array(false, WC_Validation::is_phone('+00.000.00.00.000')), array(false, WC_Validation::is_phone('+00 aaa dd ee fff')));
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:9,代码来源:validation.php

示例2: save_address

 /**
  * Save and and update a billing or shipping address if the
  * form was submitted through the user account page.
  */
 public static function save_address()
 {
     global $wp;
     if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
         return;
     }
     if (empty($_POST['action']) || 'edit_address' !== $_POST['action'] || empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-edit_address')) {
         return;
     }
     $user_id = get_current_user_id();
     if ($user_id <= 0) {
         return;
     }
     $load_address = isset($wp->query_vars['edit-address']) ? wc_edit_address_i18n(sanitize_title($wp->query_vars['edit-address']), true) : 'billing';
     $address = WC()->countries->get_address_fields(esc_attr($_POST[$load_address . '_country']), $load_address . '_');
     foreach ($address as $key => $field) {
         if (!isset($field['type'])) {
             $field['type'] = 'text';
         }
         // Get Value.
         switch ($field['type']) {
             case 'checkbox':
                 $_POST[$key] = (int) isset($_POST[$key]);
                 break;
             default:
                 $_POST[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : '';
                 break;
         }
         // Hook to allow modification of value.
         $_POST[$key] = apply_filters('woocommerce_process_myaccount_field_' . $key, $_POST[$key]);
         // Validation: Required fields.
         if (!empty($field['required']) && empty($_POST[$key])) {
             wc_add_notice(sprintf(__('%s is a required field.', 'woocommerce'), $field['label']), 'error');
         }
         if (!empty($_POST[$key])) {
             // Validation rules.
             if (!empty($field['validate']) && is_array($field['validate'])) {
                 foreach ($field['validate'] as $rule) {
                     switch ($rule) {
                         case 'postcode':
                             $_POST[$key] = strtoupper(str_replace(' ', '', $_POST[$key]));
                             if (!WC_Validation::is_postcode($_POST[$key], $_POST[$load_address . '_country'])) {
                                 wc_add_notice(__('Please enter a valid postcode / ZIP.', 'woocommerce'), 'error');
                             } else {
                                 $_POST[$key] = wc_format_postcode($_POST[$key], $_POST[$load_address . '_country']);
                             }
                             break;
                         case 'phone':
                             $_POST[$key] = wc_format_phone_number($_POST[$key]);
                             if (!WC_Validation::is_phone($_POST[$key])) {
                                 wc_add_notice(sprintf(__('%s is not a valid phone number.', 'woocommerce'), '<strong>' . $field['label'] . '</strong>'), 'error');
                             }
                             break;
                         case 'email':
                             $_POST[$key] = strtolower($_POST[$key]);
                             if (!is_email($_POST[$key])) {
                                 wc_add_notice(sprintf(__('%s is not a valid email address.', 'woocommerce'), '<strong>' . $field['label'] . '</strong>'), 'error');
                             }
                             break;
                     }
                 }
             }
         }
     }
     do_action('woocommerce_after_save_address_validation', $user_id, $load_address, $address);
     if (0 === wc_notice_count('error')) {
         foreach ($address as $key => $field) {
             update_user_meta($user_id, $key, $_POST[$key]);
         }
         wc_add_notice(__('Address changed successfully.', 'woocommerce'));
         do_action('woocommerce_customer_save_address', $user_id, $load_address);
         wp_safe_redirect(wc_get_endpoint_url('edit-address', '', wc_get_page_permalink('myaccount')));
         exit;
     }
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:79,代码来源:class-wc-form-handler.php

示例3: process_checkout

 /**
  * Process the checkout after the confirm order button is pressed
  *
  * @access public
  * @return void
  */
 public function process_checkout()
 {
     global $wpdb, $current_user;
     wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout');
     if (!defined('WOOCOMMERCE_CHECKOUT')) {
         define('WOOCOMMERCE_CHECKOUT', true);
     }
     // Prevent timeout
     @set_time_limit(0);
     do_action('woocommerce_before_checkout_process');
     if (sizeof(WC()->cart->get_cart()) == 0) {
         wc_add_notice(sprintf(__('Sorry, your session has expired. <a href="%s" class="wc-backward">Return to homepage</a>', 'woocommerce'), home_url()), 'error');
     }
     do_action('woocommerce_checkout_process');
     // Checkout fields (not defined in checkout_fields)
     $this->posted['terms'] = isset($_POST['terms']) ? 1 : 0;
     $this->posted['createaccount'] = isset($_POST['createaccount']) ? 1 : 0;
     $this->posted['payment_method'] = isset($_POST['payment_method']) ? stripslashes($_POST['payment_method']) : '';
     $this->posted['shipping_method'] = isset($_POST['shipping_method']) ? $_POST['shipping_method'] : '';
     $this->posted['ship_to_different_address'] = isset($_POST['ship_to_different_address']) ? true : false;
     if (isset($_POST['shiptobilling'])) {
         _deprecated_argument('WC_Checkout::process_checkout()', '2.1', 'The "shiptobilling" field is deprecated. THe template files are out of date');
         $this->posted['ship_to_different_address'] = $_POST['shiptobilling'] ? false : true;
     }
     // Ship to billing only option
     if (WC()->cart->ship_to_billing_address_only()) {
         $this->posted['ship_to_different_address'] = false;
     }
     // Update customer shipping and payment method to posted method
     $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
     if (isset($this->posted['shipping_method']) && is_array($this->posted['shipping_method'])) {
         foreach ($this->posted['shipping_method'] as $i => $value) {
             $chosen_shipping_methods[$i] = wc_clean($value);
         }
     }
     WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
     WC()->session->set('chosen_payment_method', $this->posted['payment_method']);
     // Note if we skip shipping
     $skipped_shipping = false;
     // Get posted checkout_fields and do validation
     foreach ($this->checkout_fields as $fieldset_key => $fieldset) {
         // Skip shipping if not needed
         if ($fieldset_key == 'shipping' && ($this->posted['ship_to_different_address'] == false || !WC()->cart->needs_shipping())) {
             $skipped_shipping = true;
             continue;
         }
         // Ship account if not needed
         if ($fieldset_key == 'account' && (is_user_logged_in() || $this->must_create_account == false && empty($this->posted['createaccount']))) {
             continue;
         }
         foreach ($fieldset as $key => $field) {
             if (!isset($field['type'])) {
                 $field['type'] = 'text';
             }
             // Get Value
             switch ($field['type']) {
                 case "checkbox":
                     $this->posted[$key] = isset($_POST[$key]) ? 1 : 0;
                     break;
                 case "multiselect":
                     $this->posted[$key] = isset($_POST[$key]) ? implode(', ', array_map('wc_clean', $_POST[$key])) : '';
                     break;
                 case "textarea":
                     $this->posted[$key] = isset($_POST[$key]) ? wp_strip_all_tags(wp_check_invalid_utf8(stripslashes($_POST[$key]))) : '';
                     break;
                 default:
                     $this->posted[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : '';
                     break;
             }
             // Hooks to allow modification of value
             $this->posted[$key] = apply_filters('woocommerce_process_checkout_' . sanitize_title($field['type']) . '_field', $this->posted[$key]);
             $this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]);
             // Validation: Required fields
             if (isset($field['required']) && $field['required'] && empty($this->posted[$key])) {
                 wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is a required field.', 'woocommerce'), 'error');
             }
             if (!empty($this->posted[$key])) {
                 // Validation rules
                 if (!empty($field['validate']) && is_array($field['validate'])) {
                     foreach ($field['validate'] as $rule) {
                         switch ($rule) {
                             case 'postcode':
                                 $this->posted[$key] = strtoupper(str_replace(' ', '', $this->posted[$key]));
                                 if (!WC_Validation::is_postcode($this->posted[$key], $_POST[$fieldset_key . '_country'])) {
                                     wc_add_notice(__('Please enter a valid postcode/ZIP.', 'woocommerce'), 'error');
                                 } else {
                                     $this->posted[$key] = wc_format_postcode($this->posted[$key], $_POST[$fieldset_key . '_country']);
                                 }
                                 break;
                             case 'phone':
                                 $this->posted[$key] = wc_format_phone_number($this->posted[$key]);
                                 if (!WC_Validation::is_phone($this->posted[$key])) {
                                     wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'), 'error');
                                 }
//.........这里部分代码省略.........
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:101,代码来源:class-wc-checkout.php

示例4: validate_posted_data

 /**
  * Validates the posted checkout data based on field properties.
  *
  * @since  2.7.0
  * @param  array $data An array of posted data.
  * @param  WP_Error $errors
  */
 protected function validate_posted_data(&$data, &$errors)
 {
     foreach ($this->get_checkout_fields() as $fieldset_key => $fieldset) {
         if ($this->maybe_skip_fieldset($fieldset_key, $data)) {
             continue;
         }
         foreach ($fieldset as $key => $field) {
             if (!isset($data[$key])) {
                 continue;
             }
             $required = !empty($field['required']);
             $format = array_filter(isset($field['validate']) ? (array) $field['validate'] : array());
             $field_label = isset($field['label']) ? $field['label'] : '';
             switch ($fieldset_key) {
                 case 'shipping':
                     /* translators: %s: field name */
                     $field_label = sprintf(__('Shipping %s', 'woocommerce'), strtolower($field_label));
                     break;
                 case 'billing':
                     /* translators: %s: field name */
                     $field_label = sprintf(__('Billing %s', 'woocommerce'), strtolower($field_label));
                     break;
             }
             if (in_array('postcode', $format)) {
                 $country = isset($data[$fieldset_key . '_country']) ? $data[$fieldset_key . '_country'] : WC()->customer->{"get_{$fieldset_key}_country"}();
                 $data[$key] = wc_format_postcode($data[$key], $country);
                 if ('' !== $data[$key] && !WC_Validation::is_postcode($data[$key], $country)) {
                     $errors->add('validation', __('Please enter a valid postcode / ZIP.', 'woocommerce'));
                 }
             }
             if (in_array('phone', $format)) {
                 $data[$key] = wc_format_phone_number($data[$key]);
                 if ('' !== $data[$key] && !WC_Validation::is_phone($data[$key])) {
                     /* translators: %s: phone number */
                     $errors->add('validation', sprintf(__('%s is not a valid phone number.', 'woocommerce'), '<strong>' . $field_label . '</strong>'));
                 }
             }
             if (in_array('email', $format)) {
                 $data[$key] = sanitize_email($data[$key]);
                 if ('' !== $data[$key] && !is_email($data[$key])) {
                     /* translators: %s: email address */
                     $errors->add('validation', sprintf(__('%s is not a valid email address.', 'woocommerce'), '<strong>' . $field_label . '</strong>'));
                 }
             }
             if ('' !== $data[$key] && in_array('state', $format)) {
                 $country = isset($data[$fieldset_key . '_country']) ? $data[$fieldset_key . '_country'] : WC()->customer->{"get_{$fieldset_key}_country"}();
                 $valid_states = WC()->countries->get_states($country);
                 if (!empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
                     $valid_state_values = array_flip(array_map('strtolower', $valid_states));
                     // Convert value to key if set
                     if (isset($valid_state_values[strtolower($data[$key])])) {
                         $data[$key] = $valid_state_values[strtolower($data[$key])];
                     }
                     if (!in_array($data[$key], array_keys($valid_states))) {
                         /* translators: 1: state field 2: valid states */
                         $errors->add('validation', sprintf(__('%1$s is not valid. Please enter one of the following: %2$s', 'woocommerce'), '<strong>' . $field_label . '</strong>', implode(', ', $valid_states)));
                     }
                 }
             }
             if ($required && '' === $data[$key]) {
                 /* translators: %s: field name */
                 $errors->add('required-field', apply_filters('woocommerce_checkout_required_field_notice', sprintf(__('%s is a required field.', 'woocommerce'), '<strong>' . $field_label . '</strong>'), $field_label));
             }
         }
     }
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:73,代码来源:class-wc-checkout.php

示例5: require_billing_information

 public static function require_billing_information($post_id, $post)
 {
     // must be shop order
     if ($post->post_type != 'shop_order') {
         return;
     }
     // only perform this check if the associated option is on
     if (self::$options->{'qsot-require-billing-information'} != 'yes') {
         return;
     }
     // only when the past is being saved in the admin
     if (!isset($_POST['action']) || $_POST['action'] != 'editpost') {
         return;
     }
     // load the order
     $order = wc_get_order($post_id);
     if (!is_object($order) || !isset($order->id)) {
         return;
     }
     // do not perform this check on cancelled orders, because they are irrelevant checks at that point
     if ('cancelled' == $order->get_status()) {
         return;
     }
     // ****** most of this is adapted from the checkout logic from WC2.3.x
     // get all the fields that we should be validating. derived from checkout process
     $fields = WC()->countries->get_address_fields(self::_get_value('_billing_country', $order), '_billing_');
     $errors = array();
     // cycle through each field, and validate the input
     foreach ($fields as $key => $field) {
         // make sure we have a field type
         if (!isset($field['type'])) {
             $field['type'] = 'text';
         }
         // find the submitted value of the field
         switch ($field['type']) {
             // checkboxes are on or off
             case 'checkbox':
                 $value = isset($_POST[$key]) ? 1 : 0;
                 break;
                 // multiselect boxes have multiple values that need cleaning
             // multiselect boxes have multiple values that need cleaning
             case 'multiselect':
                 $value = isset($_POST[$key]) ? implode(', ', array_map('wc_clean', $_POST[$key])) : '';
                 break;
                 // textareas allow for lots of text, so clean that up
             // textareas allow for lots of text, so clean that up
             case 'textarea':
                 $value = isset($_POST[$key]) ? wp_strip_all_tags(wp_check_invalid_utf8(stripslashes($_POST[$key]))) : '';
                 break;
                 // all other fields should be cleaned as well
             // all other fields should be cleaned as well
             default:
                 $value = isset($_POST[$key]) ? is_array($_POST[$key]) ? array_map('wc_clean', $_POST[$key]) : wc_clean($_POST[$key]) : '';
                 break;
         }
         // allow modification of resulting value
         $value = apply_filters('woocommerce_process_checkout_' . sanitize_title($field['type']) . '_field', $value);
         $value = apply_filters('woocommerce_process_checkout_field_' . $key, $value);
         // check required fields
         if (isset($field['required']) && $field['required'] && empty($value)) {
             $error[] = '<strong>' . $field['label'] . '</strong> ' . __('is a required field.', 'woocommerce');
         }
         // some non-empty fields need addtiional validation. handle that here
         if (!empty($value)) {
             // cycle through the rules
             if (isset($field['validate'])) {
                 foreach ($field['validate'] as $rule) {
                     // process each rule if it is in the list
                     switch ($rule) {
                         // postcodes vary from country to country
                         case 'postcode':
                             $value = strtoupper(str_replace(' ', '', $value));
                             if (!WC_Validation::is_postcode($value, $_POST[$key])) {
                                 $errors[] = __('Please enter a valid postcode/ZIP.', 'woocommerce');
                             }
                             break;
                             // phone digit count and format varies from country to country
                         // phone digit count and format varies from country to country
                         case 'phone':
                             $value = wc_format_phone_number($value);
                             if (!WC_Validation::is_phone($value)) {
                                 $errors[] = '<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce');
                             }
                             break;
                             // validate email addresses
                         // validate email addresses
                         case 'email':
                             $value = strtolower($value);
                             if (!is_email($value)) {
                                 $errors[] = '<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce');
                             }
                             break;
                             // states cound be in different formats or have different values based on the country
                         // states cound be in different formats or have different values based on the country
                         case 'state':
                             $states = WC()->countries->get_states(self::_get_value('_billing_country', $order));
                             if (!empty($states) && is_array($states)) {
                                 $states = array_flip(array_map('strtolower', $states));
                                 // look up correct value if key exists
                                 if (isset($states[strtolower($value)])) {
//.........这里部分代码省略.........
开发者ID:galapas,项目名称:opentickets-community,代码行数:101,代码来源:admin.class.php

示例6: save_address_book

        function save_address_book()
        {
            global $woocommerce;
            $this->load_cart_files();
            $checkout = new WC_Checkout();
            $user = wp_get_current_user();
            $address = $_POST['address'];
            $shipFields = $woocommerce->countries->get_address_fields($address['shipping_country'], 'shipping_');
            $errors = array();
            foreach ($shipFields as $key => $field) {
                if (isset($field['required']) && $field['required'] && empty($address[$key])) {
                    $errors[] = $key;
                }
                if (!empty($address[$key])) {
                    // Validation rules
                    if (!empty($field['validate']) && is_array($field['validate'])) {
                        foreach ($field['validate'] as $rule) {
                            switch ($rule) {
                                case 'postcode':
                                    $address[$key] = strtoupper(str_replace(' ', '', $address[$key]));
                                    if (!WC_Validation::is_postcode($address[$key], $address['shipping_country'])) {
                                        $errors[] = $key;
                                        wc_add_notice(__('Please enter a valid postcode/ZIP.', 'woocommerce'), 'error');
                                    } else {
                                        $address[$key] = wc_format_postcode($address[$key], $address['shipping_country']);
                                    }
                                    break;
                                case 'phone':
                                    $address[$key] = wc_format_phone_number($address[$key]);
                                    if (!WC_Validation::is_phone($address[$key])) {
                                        $errors[] = $key;
                                        if (function_exists('wc_add_notice')) {
                                            wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'), 'error');
                                        } else {
                                            $woocommerce->add_error('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'));
                                        }
                                    }
                                    break;
                                case 'email':
                                    $address[$key] = strtolower($address[$key]);
                                    if (!is_email($address[$key])) {
                                        $errors[] = $key;
                                        if (function_exists('wc_add_notice')) {
                                            wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'), 'error');
                                        } else {
                                            $woocommerce->add_error('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'));
                                        }
                                    }
                                    break;
                                case 'state':
                                    // Get valid states
                                    $valid_states = WC()->countries->get_states($address['shipping_country']);
                                    if ($valid_states) {
                                        $valid_state_values = array_flip(array_map('strtolower', $valid_states));
                                    }
                                    // Convert value to key if set
                                    if (isset($valid_state_values[strtolower($address[$key])])) {
                                        $address[$key] = $valid_state_values[strtolower($address[$key])];
                                    }
                                    // Only validate if the country has specific state options
                                    if (is_array($valid_states) && sizeof($valid_states) > 0) {
                                        if (!in_array($address[$key], array_keys($valid_states))) {
                                            $errors[] = $key;
                                            if (function_exists('wc_add_notice')) {
                                                wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not valid. Please enter one of the following:', 'woocommerce') . ' ' . implode(', ', $valid_states), 'error');
                                            } else {
                                                $woocommerce->add_error('<strong>' . $field['label'] . '</strong> ' . __('is not valid. Please enter one of the following:', 'woocommerce') . ' ' . implode(', ', $valid_states));
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                }
            }
            if (count($errors) > 0) {
                die(json_encode(array('ack' => 'ERR', 'errors' => $errors, 'message' => __('Please enter the complete address', 'wc_shipping_multiple_address'))));
            }
            $id = $_POST['id'];
            $addresses = $this->get_user_addresses($user);
            $redirect_url = isset($_POST['next']) ? $_POST['next'] : get_permalink(woocommerce_get_page_id('multiple_addresses'));
            if ($id >= 0) {
                $next = add_query_arg('updated', '1', $redirect_url);
            } else {
                $next = add_query_arg('new', '1', $redirect_url);
            }
            // address is unique, save!
            if ($id == -1) {
                $vals = '';
                foreach ($address as $key => $value) {
                    $vals .= $value;
                }
                $md5 = md5($vals);
                foreach ($addresses as $addr) {
                    $vals = '';
                    if (!is_array($addr)) {
                        continue;
                    }
                    foreach ($addr as $key => $value) {
//.........这里部分代码省略.........
开发者ID:RainyDayMedia,项目名称:carbide-probes,代码行数:101,代码来源:woocommerce-shipping-multiple-address.php

示例7: subscription_address

    /**
     * Edit subscription shipping address
     * 
     * @access public
     * @param int $subscription_id
     * @return void
     */
    public static function subscription_address($subscription_id)
    {
        if ($subscription = self::get_subscription($subscription_id)) {
            if (!$subscription->needs_shipping() || !apply_filters('subscriptio_allow_shipping_address_edit', true)) {
                self::redirect_to_subscription($subscription);
                return;
            }

            // Form submitted?
            if (isset($_POST['action']) && $_POST['action'] == 'subscriptio_edit_address') {

                // Validate address WooCommerce-style
                $address = WC()->countries->get_address_fields(esc_attr($_POST['shipping_country' ]), 'shipping_');

                foreach ($address as $key => $field) {

                    // Make sure we have field type before proceeding
                    $field['type'] = isset($field['type']) ? $field['type'] : 'text';

                    // Sanitize values
                    if ($field['type'] == 'checkbox') {
                        $_POST[$key] = isset($_POST[$key]) ? 1 : 0;
                    }
                    else {
                        $_POST[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : '';
                    }

                    // Required field empty?
                    if (!empty($field['required']) && empty($_POST[$key])) {
                        wc_add_notice($field['label'] . ' ' . __('is a required field.', 'subscriptio'), 'error');
                    }

                    // Validate field according to rules
                    if (!empty($field['validate']) && is_array($field['validate'])) {
                        foreach ($field['validate'] as $rule) {
                            if ($rule == 'postcode') {
                                $_POST[$key] = strtoupper(str_replace(' ', '', $_POST[$key]));

                                if (WC_Validation::is_postcode($_POST[$key], $_POST['shipping_country'])) {
                                    $_POST[$key] = wc_format_postcode($_POST[$key], $_POST['shipping_country']);
                                } else {
                                    wc_add_notice(__('Please enter a valid postcode/ZIP.', 'subscriptio'), 'error');
                                }
                            }
                            else if ($rule == 'phone') {
                                $_POST[$key] = wc_format_phone_number($_POST[$key]);

                                if (!WC_Validation::is_phone($_POST[$key])) {
                                    wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'subscriptio'), 'error');
                                }
                            }
                            else if ($rule == 'email') {
                                $_POST[$key] = strtolower($_POST[$key]);

                                if (!is_email($_POST[$key])) {
                                    wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'), 'error');
                                }
                            }
                        }
                    }
                }

                // No errors in form?
                if (wc_notice_count('error') == 0) {

                    // Try to save address
                    if ($subscription->update_shipping_address($_POST, true, true)) {
                        wc_add_notice(__('Shipping address has been updated.', 'subscriptio'));
                    }

                    // Something went really wrong...
                    else {
                        wc_add_notice(__('Something went wrong...', 'subscriptio'), 'error');
                    }

                    // Redirect to subscription page
                    self::redirect_to_subscription($subscription);
                }
                else {
                    self::display_address_form($subscription);
                }
            }

            // Display form
            else {
                self::display_address_form($subscription);
            }
        }
    }
开发者ID:qhuit,项目名称:dcosta,代码行数:96,代码来源:subscriptio-my-account.class.php


注:本文中的WC_Validation::is_phone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。