05 June 2020

Hide wordpress tool bar

Hide wordpress tool bar




add_filter('show_admin_bar', '__return_false');

Login with Phone number in Woocommerce WordPress

Login with Phone number in Woocommerce WordPress



function wooc_add_phone_number_field() {
    return apply_filters( 'woocommerce_forms_field', array(
        'wooc_user_phone' => array(
            'type'        => 'text',
            'label'       => __( 'Phone Number', ' woocommerce' ),
            'placeholder' => __( 'Your phone number', 'woocommerce' ),
            'required'    => true,
        ),
    ) );
}
add_action( 'woocommerce_register_form', 'wooc_add_field_to_registeration_form', 15 );
function wooc_add_field_to_registeration_form() {
    $fields = wooc_add_phone_number_field();
    foreach ( $fields as $key => $field_args ) {
        woocommerce_form_field( $key, $field_args );
    }
}

add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
function wooc_save_extra_register_fields( $customer_id ) {
    if (isset($_POST['wooc_user_phone'])){
        update_user_meta( $customer_id, 'wooc_user_phone', sanitize_text_field( $_POST['wooc_user_phone'] ) );
    }
}

function wooc_get_users_by_phone($phone_number){
    $user_query = new \WP_User_Query( array(
        'meta_key' => 'wooc_user_phone',
        'meta_value' => $phone_number,
        'compare'=> '='
    ));
    return $user_query->get_results();
}

add_filter('authenticate','wooc_login_with_phone',30,3);
function wooc_login_with_phone($user, $username, $password ){
    if($username != ''){
        $users_with_phone = wooc_get_users_by_phone($username);
        if(empty($users_with_phone)){
            return $user;
}
$phone_user = $users_with_phone[0];

if ( wp_check_password( $password, $phone_user->user_pass, $phone_user->ID ) ){
return $phone_user;
}
    }
    return $user;
}

add_filter( 'gettext', 'wooc_change_login_label', 10, 3 );
function wooc_change_login_label( $translated, $original, $domain ) {
    if ( $translated == "Username or email address" && $domain === 'woocommerce' ) {
        $translated = "Username or email address or phone";
    }
    return $translated;
}

How to hide wordpress tool bar?

 Hide wordpress tool bar


add_filter('show_admin_bar', '__return_false');

How to logout on any page after woocommerce and wordpress Logout?

 Logout on any page after woocommerce  and wordpress Logout



add_action('wp_logout','ps_redirect_after_logout');
function ps_redirect_after_logout(){
         wp_redirect( 'your url here' );
         exit();
}

04 June 2020

How to get user is login or not login in woocommerce and wordpress?

User is login or not login in woocommerce and wordpress



if ( is_user_logged_in() ) {

// echo '<script>alert("your are login");</script>';

} else {



}

How to get page name from url in php?


Get page name from url in php.


 $slug = basename(get_permalink());

How to run jquery after page is fully loaded in background?

Run jquery after page is fully loaded in background

jQuery(document).ready(function($) { 
  $(window).load(function() { 
     //insert all your ajax callback code here. 
     //Which will run only after page is fully loaded in background.
  });
});

Hide wordpress tool bar

Hide wordpress tool bar add_filter('show_admin_bar', '__return_false');