WooCommerce自定义登录和注册

时间:2017-07-18 15:36:59

标签: php wordpress woocommerce e-commerce

我有一个包含emailpassword字段的自定义登录和注册表单。如何将它们用作WooCommerce登录和注册表单,因此当我点击Sign In按钮时,它会显示商店的所有产品?

  global $wpdb;
  if($_SERVER["REQUEST_METHOD"] == "POST") {
  $username = $wpdb->escape($_REQUEST['username']);
  $password = $wpdb->escape($_REQUEST['password']);
  $_SESSION['username'] = $username;
  $wpdb->get_results("select * from wp_registration where     Email='$username' AND Password='$password'");
  $count=  $wpdb->num_rows;
   if($count == 1) {  
    echo"<script>alert('Welcome')</script>";
    header('Location:index.php');
   }  
  else {
    echo"<script>alert('Incorrect Username or Password!')</script>";
    }  
   }
   ?>



 <input type="text"  style="font-size: xx-large !important;"  placeholder="Username" onfocus="this.placeholder=''" onblur="this.placeholder = 'Username'" name="username" required>

   <input type="password" style="font-size: xx-large !important;"  placeholder="password" onfocus="this.placeholder=''" onblur="this.placeholder = 'password'" name="password" required>

   <span class="psw"><input type="submit">Submit</span>

1 个答案:

答案 0 :(得分:0)

if (isset($_POST['signup'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $creds = array();
    $creds['user_login'] = $username;
    $creds['user_password'] = $password;
    $creds['remember'] = false;
    $user = wp_signon($creds, false);
    if (is_wp_error($user)) {
        echo"<script>alert('Incorrect Username or Password!')</script>";
    } else {
        echo"<script>alert('Welcome')</script>";
        header('Location:index.php');
    }
}
?>


<form method="post">
 <input type="text"  style="font-size: xx-large !important;"  placeholder="Username" onfocus="this.placeholder=''" onblur="this.placeholder = 'Username'" name="username" required>

   <input type="password" style="font-size: xx-large !important;"  placeholder="password" onfocus="this.placeholder=''" onblur="this.placeholder = 'password'" name="password" required>

   <span class="psw"><input name="signup" type="submit">Submit</span>
</form>