WooCommerce结帐时显示并保存WordPress用户社交登录配置文件URL

时间:2019-10-11 09:49:44

标签: php wordpress woocommerce

我正在尝试从bboomer(https://businessbloomer.com/woocommerce-display-save-wp-user-field-e-g-user_url-checkout/)更新此有用的代码片段,以在woocommerce结帐时显示并保存用户社交网络个人资料页面。个人资料网址在使用社交登录插件登录后保存在用户元数据中,如果我能将其显示在结帐页面上,那将是惊人的。不管我做什么,我都无法正常工作。

不知道是否有帮助,但是使用JSM的Show User Meta,当用户使用Twitter登录时,我可以在用户个人资料中看到以下内容:

显示用户元数据

密钥

_wc_social_login_twitter_profile

VALUE

array (
  0 => 
  array (
    'identifier' => 720540,
'web_site_url' => NULL,
'profile_url' => 'http://twitter.com/usersprofilepage',
'photo_url' => 'http://pbs.twimg.com/profile_images/710794325690464512/pvqrktNk.jpg',
'display_name' => 'john doe',
'description' => '',
'first_name' => 'John',
'last_name' => 'Doe',
'gender' => NULL,
'language' => NULL,
'age' => NULL,
'birth_day' => NULL,
'birth_month' => NULL,
'birth_year' => NULL,
'email' => '',
'email_verified' => '',
'phone' => NULL,
'address' => NULL,
'country' => NULL,
'region' => 'London',
'city' => NULL,
'zip' => NULL,
'job_title' => NULL,
'organization_name' => NULL,
  ),
)

我在这里。

// ------------------------
// 1. Display field @ Checkout

add_action( 'woocommerce_after_checkout_billing_form',         
'bbloomer_add_user_field_to_checkout' );

function bbloomer_add_user_field_to_checkout( $checkout ) {

$current_user = wp_get_current_user();
$saved_url->profile_url;

woocommerce_form_field( 'profile_url', array(        
'type' => 'text',        
'class' => array('profile_url form-row-wide'),        
'label' => __('Profile URL'),        
'placeholder' => __('http://socialnetwork.com/yourprofile'),        
'required' => false
), 
$saved_url ); 

}


// ------------------------
// 2. Save Field Into User Meta

add_action( 'woocommerce_checkout_update_user_meta', 
'bbloomer_checkout_field_update_user_meta' );

function bbloomer_checkout_field_update_user_meta( $user_id ) { 

if ( $user_id && $_POST['profile_url'] ) {

// once again, use "profile_url"

   $args = array(
                'ID' => $user_id,
                'profile_url' => esc_attr( $_POST['profile_url'] )
        );      

    wp_update_user( $args );
}

}

请让我知道我要去哪里了!

如果有可能使它起作用,那么无论他们使用哪个社交帐户(例如Twitter,Facebook,LinkedIn或Instagram)登录,我都需要做些什么来修改代码,使其显示并保存个人资料网址。

非常感谢!

0 个答案:

没有答案