【问题标题】:Data storing in the Database, Wordpress WooCommerce数据存储在数据库中,Wordpress WooCommerce
【发布时间】:2014-06-04 06:49:43
【问题描述】:

我目前正在编写以下代码,但似乎没有让我的数据库与 woocommerce 交互,这是一个注册/注册表单,所以信息基本上只需要发布到数据库,以便记录何时用户需要使用吗?但是,我设法让它记录了密码/名字等所有内容,但与 woocommerce 无关,例如帐单地址,这是我的代码,希望您能提供帮助!

<div id="content">
<div class="titlebox" ><center><?php the_title(); ?></center></div>

<div class="description">
<center>
<strong><h2>Create an Account</h2></strong>
</center>
</div>

<?php
$err = '';
$success = '';

global $wpdb, $PasswordHash, $current_user, $user_ID;

if(isset($_POST['task']) && $_POST['task'] == 'register' ) {

    $pwd1 = $wpdb->escape(trim($_POST['pwd1']));
    $pwd2 = $wpdb->escape(trim($_POST['pwd2']));
    $first_name = $wpdb->escape(trim($_POST['first_name']));
    $last_name = $wpdb->escape(trim($_POST['last_name']));
    $description = $wpdb->escape(trim($_POST['description']));
    $email = $wpdb->escape(trim($_POST['email']));
    $username = $wpdb->escape(trim($_POST['username']));
    $url = $wpdb->escape(trim($_POST['url']));
    $aim = $wpdb->escape(trim($_POST['aim']));
    $yim = $wpdb->escape(trim($_POST['yim']));
    $jabber = $wpdb->escape(trim($_POST['jabber']));
    $googleplus = $wpdb->escape(trim($_POST['googleplus']));
    $billing_first_name = $wpdb->escape(trim($_POST['billing_first_name']));
    $billing_last_name = $wpdb->escape(trim($_POST['billing_last_name']));
    $billing_company = $wpdb->escape(trim($_POST['billing_company']));
    $billing_address_1 = $wpdb->escape(trim($_POST['billing_address_1']));
    $billing_address_2 = $wpdb->escape(trim($_POST['billing_address_2']));
    $billing_city = $wpdb->escape(trim($_POST['billing_city']));
    $billing_postcode = $wpdb->escape(trim($_POST['billing_postcode']));
    $billing_state = $wpdb->escape(trim($_POST['billing_state']));
    $billing_country = $wpdb->escape(trim($_POST['billing_country']));
    $billing_phone = $wpdb->escape(trim($_POST['billing_phone']));
    $billing_email = $wpdb->escape(trim($_POST['billing_email']));

    if( $email == "" || $pwd1 == "" || $pwd2 == "" || $username == "" || $first_name == "" || $last_name == "" || $description == "" ) {
        $err = 'Please don\'t leave the required fields.';
    } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $err = 'Invalid email address.';
    } else if(email_exists($email) ) {
        $err = 'Email already exist.';
    } else if($pwd1 <> $pwd2 ){
        $err = 'Password do not match.';        
    } else {
        $user_id = wp_insert_user( array (
        'first_name'    => apply_filters('pre_user_first_name', $first_name), 
        'last_name'     => apply_filters('pre_user_last_name', $last_name),
        'url'           => apply_filters('pre_user_url', $url),
        'aim'           => apply_filters('pre_user_aim', $aim),
        'yim'           => apply_filters('pre_user_yim', $yim),
        'jabber'        => apply_filters('pre_user_jabber', $jabber),
        'googleplus'    => apply_filters('pre_user_googleplus', $googleplus),
        'description'   => apply_filters('pre_user_description', $description), 
        'user_pass'     => apply_filters('pre_user_pass', $pwd1), 
        'user_login'    => apply_filters('pre_user_login', $username), 
        'user_email'    => apply_filters('pre_user_email', $email), 
        'role'          => 'subscriber' 
        ) );
        if( is_wp_error($user_id) ) {
            $err = 'Error on user creation.';
        } else {
            do_action('user_register', $user_id);

            $success = 'You\'re successfully register';
        }
    }
}
?>

<div id="message">
    <?php 
        if(! empty($err) ) :
            echo '<p class="error">'.$err.'</p>';
        endif;
    ?>

    <?php 
        if(! empty($success) ) :
            echo '<p class="error">'.$success.'</p>';
        endif;
    ?>
</div>

<form method="post">
    <h3>Create Account.</h3>
    <p><label>Last Name</label></p>
    <p><input type="text" value="" name="last_name" id="last_name" /></p>
    <p><label>First Name</label></p>
    <p><input type="text" value="" name="first_name" id="first_name" /></p>
    <p><label>Description</label></p>
    <p><input type="text" value="" name="description" id="description" /></p>
    <p><label>url</label></p>
    <p><input type="text" value="" name="url" id="url" /></p>
    <p><label>aim</label></p>
    <p><input type="text" value="" name="aim" id="aim" /></p>
    <p><label>yim</label></p>
    <p><input type="text" value="" name="yim" id="yim" /></p>
    <p><label>jabber</label></p>
    <p><input type="text" value="" name="jabber" id="jabber" /></p>
    <p><label>googleplus</label></p>
    <p><input type="text" value="" name="googleplus" id="googleplus" /></p>
    <p><label>Email</label></p>
    <p><input type="text" value="" name="email" id="email" /></p>
    <p><label>Username</label></p>
    <p><input type="text" value="" name="username" id="username" /></p>
    <p><label>Password</label></p>
    <p><input type="password" value="" name="pwd1" id="pwd1" /></p>
    <p><label>Password again</label></p>
    <p><input type="password" value="" name="pwd2" id="pwd2" /></p>
    <p><label>Billing First Name</label></p>
    <p><input type="text" value="" name="billing_first_name" id="billing_first_name" /></p>
    <p><label>Billing Second Name</label></p>
    <p><input type="text" value="" name="billing_last_name" id="billing_last_name" /></p>
    <p><label>Billing Company</label></p>
    <p><input type="text" value="" name="billing_last_name" id="billing_last_name" /></p>
    <p><label>Billing Address Line 1</label></p>
    <p><input type="text" value="" name="billing_address_1" id="billing_address_1" /></p>
    <p><label>Billing Address Line 2</label></p>
    <p><input type="text" value="" name="billing_address_2" id="billing_address_2" /></p>
    <p><label>Billing City</label></p>
    <p><input type="text" value="" name="billing_city" id="billing_city" /></p>
    <p><label>Billing Postcode</label></p>
    <p><input type="text" value="" name="billing_postcode" id="billing_postcode" /></p>
    <p><label>Billing State</label></p>
    <p><input type="text" value="" name="billing_state" id="billing_state" /></p>
    <p><label>Billing Country</label></p>
    <p><input type="text" value="" name="billing_country" id="billing_country" /></p>
    <p><label>Billing Phone</label></p>
    <p><input type="text" value="" name="billing_phone" id="billing_phone" /></p>
    <p><label>Billing Email</label></p>
    <p><input type="text" value="" name="billing_email" id="billing_email" /></p>
    <div class="alignleft"><p><?php if($sucess != "") { echo $sucess; } ?> <?php if($err != "") { echo $err; } ?></p></div>
    <button type="submit" name="btnregister" class="button" >Submit</button>
    <input type="hidden" name="task" value="register" />
</form>

【问题讨论】:

    标签: php database wordpress woocommerce woothemes


    【解决方案1】:

    我发现数据库中的数据表是“fj2a27xri_usermeta”,并且该表中标记为元键的单元格中有以下内容:这是我使用的所有这些,但仍然没有计费和运输记录?

    1-  first_name
    2 - last_name
    3 - description
    4 - email
    5 - username 
    6 - url 
    7 - aim
    8 - yim
    9 - jabber
    10 - googleplus     
    11 - billing_first_name 
    12 - billing_last_name
    13 - billing_company 
    14 - billing_address_1
    15 - billing_address_2
    16 - billing_city 
    17 - billing_postcode 
    18 - billing_state 
    19 - billing_country 
    20 - billing_phone 
    21 - billing_email
    

    1-10 工作而 11-21 不工作?

    【讨论】:

      【解决方案2】:

      我不知道 WooCommerce 使用的所有元值,并且我附近没有安装 WordPress,我主要是在处理我过去使用 WP 时所知道的。试试这个,

      在 WordPress GUI 中创建一个新的购物者帐户并填写该用户的每个信息字段。然后转到您的数据库管理器,例如 phpMyAdmin 或其他任何可以让您直接访问数据库的工具,并查看用户元表以查看您需要的信息。 :/ 恐怕我能给你的细节就这么多了。

      【讨论】:

        【解决方案3】:

        我明白你在做什么。 WP API 运行正常,但您没有对 WooCommerce API 的任何调用,这就是它没有在 WooCommerce 方面更新任何内容的原因。这是您想要的 API:

        http://docs.woothemes.com/wc-apidocs/class-WC_Customer.html

        编辑

        所以经过一番研究,我发现 WooCommerce 用户信息与正常使用数据一起存储在 WordPress 数据库的用户元表中。因此,要更新相关的 WooCommerce 信息,只需查看数据库中的该表并找到您要添加/更新的值的名称。

        update_user_meta($userId, 'company', $companydata);
        

        【讨论】:

        • 我还是有点困惑,我对这一切都很陌生,可能会更具体一点:)
        • 没问题。我试图尽可能多地扩展这个话题。
        • update_user_meta($userId, 'company', $companydata); update_user_meta($userId, 'address_1', $address_1data);每一个人?还是我仍然在 100 英里之外哈哈:/
        • 或者可以编辑我的添加一行作为示例?
        猜你喜欢
        • 2018-10-08
        • 2018-04-10
        • 2016-09-15
        • 2019-04-18
        • 1970-01-01
        • 2017-08-16
        • 2013-12-13
        • 1970-01-01
        • 2011-12-06
        相关资源
        最近更新 更多