是否有示例代码以编程方式为Dokan插件创建和激活卖家帐户?
我尝试了以下内容:
$email = 'abc@gmail.com';
$pwd = 'admin123';
$first_name = 'fname';
$last_name = 'lname';
$store_name = 'TestStore';
$custom_store_url = '';
$phone = '';
$newUserId = wc_create_new_customer( $email, $first_name, $pwd );
$newUser = get_user_by( 'email', $email );
update_user_meta( $newUserId, "first_name", $first_name );
update_user_meta( $newUserId, "last_name", $last_name );
update_user_meta( $newUserId, "dokan_enable_selling", 'yes' );
update_user_meta( $newUserId, "dokan_store_name", $store_name );
$user = wp_signon( array( 'user_login' => $newUser->user_login, 'user_password' => $pwd ), false );
if ( is_a( $user, 'WP_User' ) ) {
$user_id = $user->ID;
if( $user ) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
update_user_meta( $newUserId, "wp_capabilities", str_replace('customer','seller',$user->capabilities);
do_action( 'wp_login', $user->user_login );
}
}
echo $customerId = ( is_user_logged_in() ) ? get_current_user_id() : 0;exit(0);
任何人都可以验证这是正确的方法还是识别,我缺少什么?
答案 0 :(得分:-1)
$email = 'abc@gmail.com';
$pwd = 'admin123';
$first_name = 'fname';
$last_name = 'lname';
$store_name = 'TestStore';
$custom_store_url = '';
$phone = '';
$newUserId = wc_create_new_customer( $email, $first_name, $pwd );
$newUserId = wp_update_user( array( 'ID' => $newUserId,
'role' => 'seller',
'first_name' => $first_name,
'last_name' => $last_name,
) );
$newUser = get_user_by( 'email', $email );
$dokan_settings = array(
'store_name' => $store_name,
'social' => array(),
'payment' => array(),
'phone' => $phone,
'show_email' => 'no',
'location' => '',
'find_address' => '',
'dokan_category' => '',
'banner' => 0,
);
update_user_meta( $newUserId, 'dokan_enable_selling', 'yes' );
update_user_meta( $newUserId, 'dokan_profile_settings', $dokan_settings );
update_user_meta( $newUserId, 'dokan_store_name', $dokan_settings['store_name'] );
$user = wp_signon( array( 'user_login' => $newUser->user_login, 'user_password' => $pwd ), false );