是否有示例代码以编程方式创建和激活 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);
任何人都可以验证这是正确的方法或识别我所缺少的吗?