PHP snippet: get logged in username and show it on the WooCommerce checkout page in a billing field

 

PHP snippet: get logged in username and show it on the WooCommerce checkout page in a billing field


/**
 * @snippet       Get Logged In Username - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=552
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.5.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action('woocommerce_after_checkout_billing_form', 'bbloomer_get_logged_in_username');
 
function bbloomer_get_logged_in_username( $checkout ) {
 
$current_user = wp_get_current_user();
$getmemid = $current_user->user_login;
 
woocommerce_form_field( 'memb_id', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Label'),
'required' => 'true',
'placeholder' => __('Placeholder'),
), $getmemid);
 
}

No comments:

Post a Comment

Free Shipping Threshold @ Cart Page