Advertisement:

Author Topic: [HowTo] contact info on click  (Read 1411 times)

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
[HowTo] contact info on click
« on: February 25, 2016, 06:37:38 am »
If you want to make the contact informations in your listings only visible for registered user and after an user click a button, you can follow this little guide. It's pretty easy and done in under 5 minutes :)

File functions.php (in your theme folder)

add this function to the end of the file, right before the closing php tag
Code: [Select]
function toggle_contact_info() {
    if (Params::getParam('toggle_contact_info') == 'show_details') {
        echo '<div id="showContact_details">';
        // Modify the output for the user details here
        if(osc_item_show_email()) {
            echo '<p class="email"><i class="fa fa-envelope"></i> '.osc_item_contact_email().'</p>';
        }
        if (osc_user_phone() != '') {
            echo '<p class="phone"><i class="fa fa-phone"></i> '.osc_user_phone().'</p>';
        }
        // Stop modifying here
        echo '</div>';       
    } else {
        echo '
        <form id="showContact" action="'.osc_item_url().'#contact" method="post">
            <input type="hidden" name="toggle_contact_info" value="show_details" />
            <button>'.__('Show contact details', 'hidden-user-info').'</button>       
        </form>';
        echo '
        <script>
        $(document).ready(function() {   
            $(document).on("submit", "#showContact", function(event){       
                event.preventDefault();
                       
                var form    = $(this),
                    action  = form.attr("action"),
                    method  = form.attr("method"),
                    data    = form.serialize();
                   
                $.ajax({
                    url: action,
                    type: method,
                    data: data,
                    cache: false,
                    beforeSend: function(data){
                        $("#showContactInfo").fadeOut("slow");
                    },
                    success: function(data){                       
                        var source = $("<div>" + data + "<>");
                            content = source.find("#showContact_details");

                        $("#showContactInfo").html(content).fadeIn("slow");
                    }
                });       
            });
        });
        </script>';
    }
}


File item.php or item-sidebar.php (in your theme folder)

Find the place where the contact details are output, it looks like this
Code: [Select]
<?php if(osc_item_show_email()) { ?>
<p class="email"><i class="fa fa-envelope"></i><?php printf('%s'osc_item_contact_email()); ?></p>
<?php ?>
<?php if (osc_user_phone() != '') { ?>
<p class="phone"><i class="fa fa-phone"></i><?php printf('%s'osc_user_phone()); ?></p>
<?php ?>

Replace it with this code
Code: [Select]
<?php if (osc_is_web_user_logged_in()) { ?>
<div id="showContactInfo">
  <?php toggle_contact_info(); ?>
</div>
<?php ?>

Now, the contact informations will only shown, if a registered user click the button
« Last Edit: February 26, 2016, 07:06:52 pm by Liath »