• Using the following hook, I successfully displayed contact buttons on the profile page:

    add_action( ‘um_after_header_meta’, ‘my_after_header_meta’, 10, 2 );
    function my_after_header_meta( $user_id, $args ) {
    // Display phone and WhatsApp buttons
    // Show valid buttons for logged-in users
    // Show non-valid buttons for logged-out users
    // If non-valid buttons are clicked -> a login modal pops up
    }

    Problem: Some form fields are being auto-filled. For example, in the phone number field, the value appears as:

    <a href=”tel:1234567890″ rel=”nofollow” title=”Mobile Number”>1234567890</a>

    Why is this happening?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support andrewshu

    (@andrewshu)

    Hello @ochime

    Maybe you add the wrong code for the mobile number field?

    Regards.

    Thread Starter ochime

    (@ochime)

    I am confident that I did not make a mistake in adding the phone number. Here is the complete function I currently have:

    add_action(‘um_after_header_meta’, ‘my_after_header_meta’, 10, 2);
    function my_after_header_meta($user_id, $args) {

    $user_phone  = um_user('mobile_number');
    $user_whatsapp = um_user('whatsapp');
    $truncated_ponsel = !empty($user_phone) ? substr($user_phone, 0, 6) . '...' : '';
    $truncated_whatsapp = !empty($user_whatsapp) ? '62' . substr(ltrim($user_whatsapp, '0'), 0, 6) . '...' : '';
    
    if (is_user_logged_in()) {
    
        // Valid buttons for logged in users
        $phone_button = '<a href="tel:' . esc_attr($user_ponsel) . '" class="contact-button phone-button">
    
                            ' . esc_html($truncated_ponsel) . '
                        </a>';
        $wa_button = '<a href="' . esc_url('https://wa.me/' . $user_whatsapp) . '" target="_blank" class="contact-button whatsapp-button" rel="noopener">
    
                            WhatsApp
                        </a>';
    } else {
    
        // Invalid buttons for logged out users
        $phone_button = '<a href="tel:' . esc_attr($truncated_ponsel) . '" class="contact-button phone-button login-trigger">
    
                            ' . esc_html($truncated_ponsel) . '
                        </a>';
        $wa_button = '<a href="' . esc_url('https://wa.me/' . $truncated_whatsapp) . '" target="_blank" class="contact-button whatsapp-button login-trigger" rel="noopener">
    
                            WhatsApp
                        </a>';
    }
    
    echo '<div class="blok-a agent-block-c">' . $phone_button . $wa_button . '</div>';

    }


    The buttons are displayed correctly, and when the user is logged out and clicks one of the buttons, a modal popup opens.

    The problem is: The fields in the form are automatically populated as I mentioned earlier.


    Plugin Support andrewshu

    (@andrewshu)

    Hello @ochime

    I think this is browser autofill. Try to add the autocomplete=”off” attribute.

    Regards.

    Thread Starter ochime

    (@ochime)

    <font _mstmutation=”1″></font>

    @andrewshu

    Sorry for the late reply.

    I don’t think that’s the case -> autocomplete.

    I’ve created a function with the same purpose on the product page (the code used is exactly the same).
    hook : add_action(‘woocommerce_single_product_summary’, ‘display_agent_info_section’, 35);

    The result was fine.
    When the user does not log in and clicks on one of the buttons, it will pop up the login page and no information is provided in each field.

    Different things when I use hooks: add_action( ‘um_after_header_meta’, ‘my_after_header_meta’, 10, 2 );

    Can you do a test run using the function I provided and see where the error needs to be fixed?

    Thanks

    Thread Starter ochime

    (@ochime)

    add_action('um_after_header_meta', 'my_after_header_meta', 10, 2);
    function my_after_header_meta($user_id, $args) {

    $user_phone = um_user('mobile_number',$user_id);
    $user_whatsapp = um_user('whatsapp',$user_id);
    $truncated_phone = !empty($user_phone) ? substr($user_phone, 0, 6) . '...' : '';
    $truncated_whatsapp = !empty($user_whatsapp) ? '62' . substr(ltrim($user_whatsapp, '0'), 0, 6) . '...' : '';


    if (is_user_logged_in()) {
    $phone_button = '<a href="tel:' . esc_attr($user_phone) . '" class="contact-button phone-button">

    ' . esc_html($truncated_phone) . '
    </a>';
    $wa_button = '<a href="' . esc_url('https://wa.me/' . $user_whatsapp) . '" target="_blank" class="contact-button whatsapp-button" rel="noopener">

    WhatsApp
    </a>';
    } else {
    $phone_button = '<a href="tel:' . esc_attr($truncated_phone) . '" class="contact-button phone-button login-trigger">

    ' . esc_html($truncated_phone) . '
    </a>';
    $wa_button = '<a href="' . esc_url('https://wa.me/' . $truncated_whatsapp) . '" target="_blank" class="contact-button whatsapp-button login-trigger" rel="noopener">

    WhatsApp
    </a>';
    }

    echo '<div class="blok-a agent-block-c">' . $phone_button . $wa_button . '</div>';
    }

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘um_after_header_meta’ is closed to new replies.