2017-07-27 72 views
2

在網站註冊後,我想顯示一個隱藏的div div在同一頁。 但註冊後,頁面將加載並顯示相同的頁面。顯示div後的進程註冊,woocommerce

這裏的形式,handler.php

public static function process_registration() { 
    $nonce_value = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : ''; 
    $nonce_value = isset($_POST['woocommerce-register-nonce']) ? $_POST['woocommerce-register-nonce'] : $nonce_value; 

    if (! empty($_POST['register']) && wp_verify_nonce($nonce_value, 'woocommerce-register')) { 
     $username = 'no' === get_option('woocommerce_registration_generate_username') ? $_POST['username'] : ''; 
     $password = 'no' === get_option('woocommerce_registration_generate_password') ? $_POST['password'] : ''; 
     $email = $_POST['email']; 

     try { 
      $validation_error = new WP_Error(); 
      $validation_error = apply_filters('woocommerce_process_registration_errors', $validation_error, $username, $password, $email); 

      if ($validation_error->get_error_code()) { 
       throw new Exception($validation_error->get_error_message()); 
      } 

      // Anti-spam trap 
      if (! empty($_POST['email_2'])) { 
       throw new Exception(__('Anti-spam field was filled in.', 'woocommerce')); 
      } 

      $new_customer = wc_create_new_customer(sanitize_email($email), wc_clean($username), $password); 

      if (is_wp_error($new_customer)) { 
       throw new Exception($new_customer->get_error_message()); 
      } 

      if (apply_filters('woocommerce_registration_auth_new_customer', true, $new_customer)) { 
       wc_set_customer_auth_cookie($new_customer); 
      } 

      wp_safe_redirect(apply_filters('woocommerce_registration_redirect', wp_get_referer() ? wp_get_referer() : wc_get_page_permalink('myaccount'))); 
      exit; 

     } catch (Exception $e) { 
      wc_add_notice('<strong>' . __('Error', 'woocommerce') . ':</strong> ' . $e->getMessage(), 'error'); 
     } 
    } 
} 

和DIV

<div class="alert success"> 
    <span class="closebtn">&times;</span> 
    <strong>Registration Success!</strong> Check Email. 
</div> 

,這是JS代碼

jQuery('input.btn.btn-default.size-new-account').click(function() { 
    jQuery('.alert.success').show(); 
}); 

但問題,我怎麼能理解流動爲註冊,我可以使用條件或其他方式。所以notif會顯示驗證是否成功,並在加載頁面後顯示。

+0

您可以添加ID,以及如果你想 –

+0

我沒有太多在PHP上的經驗,我真的不能發佈大部分發布的代碼。所以我想直接問一下。上面的腳本允許你註冊並重定向到另一個頁面或重新加載同一頁面嗎? – Sagar

+0

實際上在註冊過程中它的好, 問題只是,當我點擊按鈕,即使我留下一切空白的通知仍然顯示,因爲我只是設置功能onclick。即使該過程未能註冊,成功通知將顯示 – Reza

回答

0

處理您的註冊(PHP代碼)後,執行下面的行

wc_add_notice('Registration successful') ; 

那麼你就不需要新的div

+0

我仍然與它混淆。 – Reza

+0

1.在您的流程註冊功能中執行一項操作,該功能將爲cookie保存一個值....說just_registered = 1 – Alice

+0

現在註冊後您的頁面會再次加載正確嗎? – Alice