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


PHP wc_notice_count函数代码示例

本文整理汇总了PHP中wc_notice_count函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_notice_count函数的具体用法?PHP wc_notice_count怎么用?PHP wc_notice_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: wc_print_notices

/**
 * Prints messages and errors which are stored in the session, then clears them.
 *
 * @since 2.1
 */
function wc_print_notices()
{
    $all_notices = WC()->session->get('wc_notices', array());
    $notice_types = apply_filters('woocommerce_notice_types', array('error', 'success', 'notice'));
    foreach ($notice_types as $notice_type) {
        if (wc_notice_count($notice_type) > 0) {
            wc_get_template("notices/{$notice_type}.php", array('messages' => $all_notices[$notice_type]));
        }
    }
    wc_clear_notices();
}
开发者ID:chhavinav,项目名称:fr.ilovejuice,代码行数:16,代码来源:wc-notice-functions.php

示例2: wc_notice_count

 /**
  * @since 1.1.0 of SA_WC_Compatibility
  */
 public static function wc_notice_count($notice_type = '')
 {
     if (self::is_wc_21()) {
         return wc_notice_count($notice_type);
     } else {
         global $woocommerce;
         if ('error' == $notice_type) {
             return $woocommerce->error_count();
         } else {
             return $woocommerce->message_count();
         }
     }
 }
开发者ID:WP-Panda,项目名称:allergenics,代码行数:16,代码来源:class-wc-compatibility.php

示例3: test_wc_notice_count

 /**
  * Test wc_notice_count().
  *
  * @since 2.2
  */
 function test_wc_notice_count()
 {
     // no error notices
     $this->assertEquals(0, wc_notice_count('error'));
     // single notice
     wc_add_notice('Bogus Notice', 'success');
     $this->assertEquals(1, wc_notice_count());
     // specific notice
     wc_add_notice('Bogus Error Notice', 'error');
     $this->assertEquals(1, wc_notice_count('error'));
     // multiple notices of different types
     wc_add_notice('Bogus Notice 2', 'success');
     wc_add_notice('Bogus Error Notice 2', 'error');
     $this->assertEquals(4, wc_notice_count());
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:20,代码来源:notice-functions.php

示例4: process_payment

 /**
  * Process the payment and return the result
  *
  * @access      public
  * @param       int $order_id
  * @return      array
  */
 public function process_payment($order_id)
 {
     if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
         if ($this->send_to_stripe($order_id)) {
             $this->order_complete();
             WC_Subscriptions_Manager::activate_subscriptions_for_order($this->order);
             $result = array('result' => 'success', 'redirect' => $this->get_return_url($this->order));
             return $result;
         } else {
             $this->payment_failed();
             // Add a generic error message if we don't currently have any others
             if (wc_notice_count('error') == 0) {
                 wc_add_notice(__('Transaction Error: Could not complete your subscription payment.', 'stripe-for-woocommerce'), 'error');
             }
         }
     } else {
         return parent::process_payment($order_id);
     }
 }
开发者ID:tccyp001,项目名称:onemore-wordpress,代码行数:26,代码来源:class-s4wc_subscriptions_gateway.php

示例5: unsubscribe_review_request

 /**
  * Handles the unsubscribe form
  *
  * @since   1.0.0
  * @return  void
  * @author  Alberto Ruggiero
  */
 public function unsubscribe_review_request()
 {
     if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
         return;
     }
     if (empty($_POST['action']) || 'unsubscribe_review_request' !== $_POST['action'] || empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'unsubscribe_review_request')) {
         return;
     }
     $customer_email = !empty($_POST['account_email']) ? sanitize_email($_POST['account_email']) : '';
     if (empty($customer_email) || !is_email($customer_email)) {
         wc_add_notice(__('Please provide a valid email address.', 'yith-woocommerce-review-reminder'), 'error');
     } elseif ($customer_email !== urldecode(base64_decode($_GET['email']))) {
         wc_add_notice(__('Please retype the email address as provided.', 'yith-woocommerce-review-reminder'), 'error');
     }
     if (wc_notice_count('error') === 0) {
         $wc_email = WC_Emails::instance();
         $email = $wc_email->emails['YWRR_Unsubscribe_Mail'];
         $email->trigger($customer_email);
         wc_add_notice(__('An email has been sent with your request', 'yith-woocommerce-review-reminder'));
         wp_safe_redirect(get_permalink(get_option('ywrr_unsubscribe_page_id')));
         exit;
     }
 }
开发者ID:yarwalker,项目名称:ecobyt,代码行数:30,代码来源:class-ywrr-form-handler.php

示例6: woocommerce__simple_auctions_winning_bid_message

/**
 * Your bid is winning message
 *
 * @access public
 * @return void
 * 
 */
function woocommerce__simple_auctions_winning_bid_message($product_id)
{
    global $product, $woocommerce;
    if ($product->product_type != 'auction') {
        return FALSE;
    }
    if ($product->is_closed()) {
        return FALSE;
    }
    $current_user = wp_get_current_user();
    if (!$current_user->ID) {
        return FALSE;
    }
    $message = __('No need to bid. Your bid is winning! ', 'wc_simple_auctions');
    if (version_compare($woocommerce->version, '2.1', ">=")) {
        if ($current_user->ID == $product->auction_current_bider && wc_notice_count() == 0) {
            wc_add_notice(apply_filters('woocommerce_simple_auctions_winning_bid_message', $message));
        }
    } else {
        if ($current_user->ID == $product->auction_current_bider && $woocommerce->message_count() == 0) {
            $woocommerce->add_message(apply_filters('woocommerce_simple_auctions_winning_bid_message', $message));
        }
    }
}
开发者ID:Omuze,项目名称:barakat,代码行数:31,代码来源:woocommerce-simple-auctions-functions.php

示例7: process_checkout

 /**
  * Process the checkout after the confirm order button is pressed.
  */
 public function process_checkout()
 {
     try {
         if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout')) {
             WC()->session->set('refresh_totals', true);
             throw new Exception(__('We were unable to process your order, please try again.', 'woocommerce'));
         }
         wc_maybe_define_constant('WOOCOMMERCE_CHECKOUT', true);
         wc_set_time_limit(0);
         do_action('woocommerce_before_checkout_process');
         if (WC()->cart->is_empty()) {
             throw new Exception(sprintf(__('Sorry, your session has expired. <a href="%s" class="wc-backward">Return to shop</a>', 'woocommerce'), esc_url(wc_get_page_permalink('shop'))));
         }
         do_action('woocommerce_checkout_process');
         $errors = new WP_Error();
         $posted_data = $this->get_posted_data();
         $this->validate_posted_data($posted_data, $errors);
         $this->validate_checkout($posted_data, $errors);
         $this->update_session($posted_data);
         $this->check_cart_items();
         do_action('woocommerce_after_checkout_validation', $posted_data, $errors);
         foreach ($errors->get_error_messages() as $message) {
             wc_add_notice($message, 'error');
         }
         if (empty($posted_data['woocommerce_checkout_update_totals']) && 0 === wc_notice_count('error')) {
             $this->process_customer($posted_data);
             $order = $this->create_order($posted_data);
             if (is_wp_error($order)) {
                 throw new Exception($order->get_error_message());
             }
             do_action('woocommerce_checkout_order_processed', $order, $posted_data);
             if (WC()->cart->needs_payment()) {
                 $this->process_order_payment($order, $posted_data['payment_method']);
             } else {
                 $this->process_order_without_payment($order);
             }
         }
     } catch (Exception $e) {
         wc_add_notice($e->getMessage(), 'error');
     }
     $this->send_ajax_failure_response();
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:45,代码来源:class-wc-checkout.php

示例8: message_count

 /**
  * @deprecated 2.1.0
  * @return int
  */
 public function message_count()
 {
     _deprecated_function('Woocommerce->message_count', '2.1', 'wc_notice_count');
     return wc_notice_count('message');
 }
开发者ID:donwea,项目名称:nhap.org,代码行数:9,代码来源:woocommerce.php

示例9: process_posted_comment_data

 /**
  * Remove contribution type prefix from posted keys
  *
  * @since 1.0.0
  */
 public function process_posted_comment_data()
 {
     $type = isset($_POST['comment_type']) ? $_POST['comment_type'] : null;
     // Bail out if not contribution type is set. This probably means
     // that this wasn't a contribution form anyway.
     if (!$type) {
         return;
     }
     // Loop over POST data and remove type prefix
     foreach ($_POST as $key => $value) {
         // Check if the key is prefixed with type
         if (strpos($key, $type . '_') === 0) {
             // Add posted value under cleaned (unprefixed) key
             $clean_key = substr($key, strlen($type) + 1);
             $_POST[$clean_key] = $value;
         }
     }
     // Process fields
     $contribution_type = wc_product_reviews_pro_get_contribution_type($type);
     foreach ($contribution_type->get_fields() as $key => $field) {
         // Get Value
         switch ($field['type']) {
             case "checkbox":
                 $_POST[$key] = isset($_POST[$key]) ? 1 : 0;
                 break;
             default:
                 $_POST[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : '';
                 break;
         }
         /**
          * Filter the POST value for $key.
          *
          * @since 1.0.0
          * @param mixed $value The POST value for $key.
          */
         $_POST[$key] = apply_filters('wc_product_reviews_pro_process_contribution_form_field_' . $key, $_POST[$key]);
         // Validation: Required fields
         if (!empty($field['required']) && empty($_POST[$key])) {
             wc_add_notice(sprintf(__('%s is a required field.', WC_Product_Reviews_Pro::TEXT_DOMAIN), $field['label']), 'error');
         }
         // Validation rules
         if (!empty($field['validate']) && is_array($field['validate'])) {
             foreach ($field['validate'] as $rule) {
                 switch ($rule) {
                     case 'email':
                         $_POST[$key] = strtolower($_POST[$key]);
                         if (!is_email($_POST[$key])) {
                             wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'error');
                         }
                         break;
                 }
             }
         }
     }
     // Check if rating is required
     if ('review' == $type && get_option('woocommerce_review_rating_required') === 'yes' && isset($_POST[$type . '_rating']) && empty($_POST[$type . '_rating'])) {
         wc_add_notice(__('Please rate the product.', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'error');
     }
     // Save/handle attachments (photos, videos)
     $attachment_type = isset($_POST['attachment_type']) ? $_POST['attachment_type'] : null;
     if ($attachment_type) {
         $key = $type . '_attachment_file';
         if (isset($_FILES[$key]) && $_FILES[$key]['size'] > 0) {
             // Only photo uploads are supported at the moment
             if ('photo' == $attachment_type) {
                 // These files need to be included as dependencies when on the front end.
                 require_once ABSPATH . 'wp-admin/includes/image.php';
                 require_once ABSPATH . 'wp-admin/includes/file.php';
                 require_once ABSPATH . 'wp-admin/includes/media.php';
                 $attachment_id = media_handle_upload($key, 0, array(), array('test_form' => false, 'mimes' => array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff')));
                 // Bail out if file upload did not succeed
                 if (is_wp_error($attachment_id)) {
                     wc_add_notice(sprintf(__('Unable to upload file: %s', WC_Product_Reviews_Pro::TEXT_DOMAIN), $attachment_id->get_error_message()), 'error');
                 } else {
                     // Keep a reference to attachment_id and type
                     $this->_uploaded_attachment_id = $attachment_id;
                     $this->_uploaded_attachment_type = $attachment_type;
                 }
             } else {
                 wc_add_notice(__('Only photo uploads are supprted at the moment', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'error');
             }
         }
         // Make sure that at least one of file or url is submitted
         if ('photo' == $type && !(isset($_FILES[$key]) && $_FILES[$key]['size'] > 0) && !(isset($_POST[$type . '_attachment_url']) && $_POST[$type . '_attachment_url'])) {
             wc_add_notice(__('Please attach a photo.', WC_Product_Reviews_Pro::TEXT_DOMAIN), 'error');
         }
     }
     // Redirect back to product page if there are errors
     if (wc_notice_count('error') > 0) {
         WC()->session->wc_product_reviews_pro_posted_data = $_POST;
         // Provide a hash so that page scrolls to form on load
         $hash = 'contribution_comment' == $type ? '#comment-' . $_POST['comment_parent'] : '#reviews';
         wp_safe_redirect(wp_get_referer() . $hash);
         exit;
     }
//.........这里部分代码省略.........
开发者ID:brian3t,项目名称:orchidmate,代码行数:101,代码来源:class-wc-product-reviews-pro-frontend.php

示例10: retrieve_password

 /**
  * Handles sending password retrieval email to customer.
  *
  * @access public
  * @uses $wpdb WordPress Database object
  * @return bool True: when finish. False: on error
  */
 public static function retrieve_password()
 {
     global $woocommerce, $wpdb;
     if (empty($_POST['user_login'])) {
         wc_add_notice(__('Enter a username or e-mail address.', 'woocommerce'), 'error');
     } elseif (strpos($_POST['user_login'], '@') && apply_filters('woocommerce_get_username_from_email', true)) {
         $user_data = get_user_by('email', trim($_POST['user_login']));
         if (empty($user_data)) {
             wc_add_notice(__('There is no user registered with that email address.', 'woocommerce'), 'error');
         }
     } else {
         $login = trim($_POST['user_login']);
         $user_data = get_user_by('login', $login);
     }
     do_action('lostpassword_post');
     if (wc_notice_count('error') > 0) {
         return false;
     }
     if (!$user_data) {
         wc_add_notice(__('Invalid username or e-mail.', 'woocommerce'), 'error');
         return false;
     }
     // redefining user_login ensures we return the right case in the email
     $user_login = $user_data->user_login;
     $user_email = $user_data->user_email;
     do_action('retrieve_password', $user_login);
     $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     if (!$allow) {
         wc_add_notice(__('Password reset is not allowed for this user', 'woocommerce'), 'error');
         return false;
     } elseif (is_wp_error($allow)) {
         wc_add_notice($allow->get_error_message, 'error');
         return false;
     }
     $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM {$wpdb->users} WHERE user_login = %s", $user_login));
     if (empty($key)) {
         // Generate something random for a key...
         $key = wp_generate_password(20, false);
         do_action('retrieve_password_key', $user_login, $key);
         // Now insert the new md5 key into the db
         $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
     }
     // Send email notification
     $mailer = WC()->mailer();
     do_action('woocommerce_reset_password_notification', $user_login, $key);
     wc_add_notice(__('Check your e-mail for the confirmation link.', 'woocommerce'));
     return true;
 }
开发者ID:chhavinav,项目名称:fr.ilovejuice,代码行数:55,代码来源:class-wc-shortcode-my-account.php

示例11: change_payment_method_via_pay_shortcode

 /**
  * Process the change payment form.
  *
  * Based on the @see woocommerce_pay_action() function.
  *
  * @access public
  * @return void
  * @since 1.4
  */
 public static function change_payment_method_via_pay_shortcode()
 {
     global $woocommerce;
     if (isset($_POST['woocommerce_change_payment']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-change_payment')) {
         $subscription_key = $_POST['woocommerce_change_payment'];
         // Pay for existing order
         $order_key = isset($_GET['key']) ? $_GET['key'] : $_GET['order'];
         $order_id = absint($_GET['order_id']);
         $order = new WC_Order($order_id);
         do_action('woocommerce_subscriptions_change_payment_method_via_pay_shortcode', $subscription_key, $order);
         ob_start();
         if ($order->id == $order_id && $order->order_key == $order_key) {
             // Set customer location to order location
             if ($order->billing_country) {
                 $woocommerce->customer->set_country($order->billing_country);
             }
             if ($order->billing_state) {
                 $woocommerce->customer->set_state($order->billing_state);
             }
             if ($order->billing_postcode) {
                 $woocommerce->customer->set_postcode($order->billing_postcode);
             }
             if ($order->billing_city) {
                 $woocommerce->customer->set_city($order->billing_city);
             }
             // Update payment method
             $new_payment_method = woocommerce_clean($_POST['payment_method']);
             self::update_recurring_payment_method($subscription_key, $order, $new_payment_method);
             $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
             // Validate
             $available_gateways[$new_payment_method]->validate_fields();
             // Process payment for the new method (with a $0 order total)
             if (function_exists('wc_notice_count')) {
                 // WC 2.1
                 if (wc_notice_count('error') == 0) {
                     $result = $available_gateways[$new_payment_method]->process_payment($order_id);
                     // Redirect to success/confirmation/payment page
                     if ($result['result'] == 'success') {
                         WC_Subscriptions::add_notice(__('Payment method updated.', 'woocommerce-subscriptions'), 'success');
                         wp_redirect($result['redirect']);
                         exit;
                     }
                 }
             } else {
                 if ($woocommerce->error_count() == 0) {
                     $result = $available_gateways[$new_payment_method]->process_payment($order_id);
                     // Redirect to success/confirmation/payment page
                     if ($result['result'] == 'success') {
                         WC_Subscriptions::add_notice(__('Payment method updated.', 'woocommerce-subscriptions'), 'success');
                         wp_redirect($result['redirect']);
                         exit;
                     }
                 }
             }
         }
     }
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:66,代码来源:class-wc-subscriptions-change-payment-gateway.php

示例12: change_payment_method_via_pay_shortcode

 /**
  * Process the change payment form.
  *
  * Based on the @see woocommerce_pay_action() function.
  *
  * @access public
  * @return void
  * @since 1.4
  */
 public static function change_payment_method_via_pay_shortcode()
 {
     if (isset($_POST['_wcsnonce']) && wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method')) {
         $subscription = wcs_get_subscription(absint($_POST['woocommerce_change_payment']));
         do_action('woocommerce_subscription_change_payment_method_via_pay_shortcode', $subscription);
         ob_start();
         if ($subscription->order_key == $_GET['key']) {
             // Set customer location to order location
             if ($subscription->billing_country) {
                 WC()->customer->set_country($subscription->billing_country);
             }
             if ($subscription->billing_state) {
                 WC()->customer->set_state($subscription->billing_state);
             }
             if ($subscription->billing_postcode) {
                 WC()->customer->set_postcode($subscription->billing_postcode);
             }
             if ($subscription->billing_city) {
                 WC()->customer->set_city($subscription->billing_city);
             }
             // Update payment method
             $new_payment_method = woocommerce_clean($_POST['payment_method']);
             // Allow some payment gateways which can't process the payment immediately, like PayPal, to do it later after the payment/sign-up is confirmed
             if (apply_filters('woocommerce_subscriptions_update_payment_via_pay_shortcode', true, $new_payment_method, $subscription)) {
                 self::update_payment_method($subscription, $new_payment_method);
             }
             $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
             // Validate
             $available_gateways[$new_payment_method]->validate_fields();
             // Process payment for the new method (with a $0 order total)
             if (wc_notice_count('error') == 0) {
                 $result = $available_gateways[$new_payment_method]->process_payment($subscription->id);
                 $result = apply_filters('woocommerce_subscriptions_process_payment_for_change_method_via_pay_shortcode', $result, $subscription);
                 // Redirect to success/confirmation/payment page
                 if ('success' == $result['result']) {
                     WC_Subscriptions::add_notice(__('Payment method updated.', 'woocommerce-subscriptions'), 'success');
                     wp_redirect($result['redirect']);
                     exit;
                 }
             }
         }
     }
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:52,代码来源:class-wc-subscriptions-change-payment-gateway.php

示例13: wc_print_notices

/**
 * Prints messages and errors which are stored in the session, then clears them.
 *
 * @since 2.1
 */
function wc_print_notices()
{
    if (!did_action('woocommerce_init')) {
        _doing_it_wrong(__FUNCTION__, __('This function should not be called before woocommerce_init.', 'woocommerce'), '2.3');
        return;
    }
    $all_notices = WC()->session->get('wc_notices', array());
    $notice_types = apply_filters('woocommerce_notice_types', array('error', 'success', 'notice'));
    foreach ($notice_types as $notice_type) {
        if (wc_notice_count($notice_type) > 0) {
            wc_get_template("notices/{$notice_type}.php", array('messages' => array_filter($all_notices[$notice_type])));
        }
    }
    wc_clear_notices();
}
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:20,代码来源:wc-notice-functions.php

示例14: process_reset_password

 /**
  * Handle reset password form
  */
 public function process_reset_password()
 {
     if (!isset($_POST['wc_reset_password'])) {
         return;
     }
     // process lost password form
     if (isset($_POST['user_login']) && isset($_POST['_wpnonce'])) {
         wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-lost_password');
         WC_Shortcode_My_Account::retrieve_password();
     }
     // process reset password form
     if (isset($_POST['password_1']) && isset($_POST['password_2']) && isset($_POST['reset_key']) && isset($_POST['reset_login']) && isset($_POST['_wpnonce'])) {
         // verify reset key again
         $user = WC_Shortcode_My_Account::check_password_reset_key($_POST['reset_key'], $_POST['reset_login']);
         if (is_object($user)) {
             // save these values into the form again in case of errors
             $args['key'] = wc_clean($_POST['reset_key']);
             $args['login'] = wc_clean($_POST['reset_login']);
             wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-reset_password');
             if (empty($_POST['password_1']) || empty($_POST['password_2'])) {
                 wc_add_notice(__('Please enter your password.', 'woocommerce'), 'error');
                 $args['form'] = 'reset_password';
             }
             if ($_POST['password_1'] !== $_POST['password_2']) {
                 wc_add_notice(__('Passwords do not match.', 'woocommerce'), 'error');
                 $args['form'] = 'reset_password';
             }
             $errors = new WP_Error();
             do_action('validate_password_reset', $errors, $user);
             if ($errors->get_error_messages()) {
                 foreach ($errors->get_error_messages() as $error) {
                     wc_add_notice($error, 'error');
                 }
             }
             if (0 == wc_notice_count('error')) {
                 WC_Shortcode_My_Account::reset_password($user, $_POST['password_1']);
                 do_action('woocommerce_customer_reset_password', $user);
                 wp_redirect(add_query_arg('reset', 'true', remove_query_arg(array('key', 'login'))));
                 exit;
             }
         }
     }
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:46,代码来源:class-wc-form-handler.php

示例15: 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_notice_count函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。