Advertisement:

Author Topic: [TUTO] Only users with complete profiles can contact  (Read 1341 times)

volunteer

  • Full Member
  • ***
  • Posts: 241
[TUTO] Only users with complete profiles can contact
« on: November 06, 2015, 02:59:23 pm »
Thanks to TESEO for this code  :)

In you ITEM.PHP add this code where it corresponds, you can use all the fields or less fields, according to you site and the info you want users to provide in their profiles:

Code: [Select]
<?php
$mandatory_fields 
= array(
    
's_country',
    
's_region',
    
's_city',
    
's_city_area',
    
's_address',
    
's_zip',
    
's_website',
    
's_phone_land',
    
's_phone_mobile',
    
'locale' // (s_info)
);
$profile_complete 1;
$user_data User::newInstance()->findByPrimaryKey(osc_logged_user_id());
foreach (
$mandatory_fields as $field) {
    if (!
$user_data[$field]) {
        
$profile_complete 0;
        break; }
} if (
$profile_complete) { ?>


////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////
////////////////// here the CODE for the contact form that you already have //////////////////
////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////

<?php } else { ?>

////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////
<a href="/user/profile" target="_blank" >YOU MUST COMPLETE YOUR PROFILE BEFORE YOU CAN CONTACT SELLERS</a>
////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////

<?php ?>


itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: [TUTO] Only users with complete profiles can contact
« Reply #1 on: January 06, 2016, 09:54:33 am »
Can the check for profile being complete to put in a function in the theme function file and then called on the item.php? Could you help with the syntax?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: [TUTO] Only users with complete profiles can contact
« Reply #2 on: January 06, 2016, 02:01:03 pm »
Hi,

1.- Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php function cust_is_profile_complete() {
    
$mandatory_fields = array(
        
's_country',
        
's_region',
        
's_city',
        
's_city_area',
        
's_address',
        
's_zip',
        
's_website',
        
's_phone_land',
        
's_phone_mobile',
        
'locale' // (s_info)
    
);
    
$profile_complete 1;
    
$user_data User::newInstance()->findByPrimaryKey(osc_logged_user_id());
    foreach (
$mandatory_fields as $field) {
        if (!
$user_data[$field]) {
            
$profile_complete 0;
            break;
        }
    
    return 
$profile_complete;
}
?>


2.- item.php:

Code: [Select]
<?php if (cust_is_profile_complete()) { ?>

////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////
////////////////// here the CODE for the contact form that you already have //////////////////
////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////

<?php } else { ?>

////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////
<a href="/user/profile" target="_blank" >YOU MUST COMPLETE YOUR PROFILE BEFORE YOU CAN CONTACT SELLERS</a>
////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// ////////////////// //////////////////

<?php ?>

Regards