BuddyDev

Search

Replies

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Thank you very much for your patience and support. You are truly remarkable. Now it works correct.

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Thank you very much for your feedback.Your code is giving the appropriate results. However the problem with this logic is that when user is checking $is_selected_food && $is_selected_movies the output is FOOD, MOVIE, FOOD & MOVIES. Actually it outputs all the 3 true cases :

    $is_selected_movies MOVIE
    $is_selected_food FOOD
    $is_selected_food && $is_selected_movies FOOD & MOVIES

    I have used only if statements inside my wp_mail.
    if ( empty( $data ) ) { // some html}
    if ( $is_selected_movies ) {// some other html}`
    if ( $is_selected_food ) { // some other html} and so on…

    If i set elseif, then i dont get correct results.

    If $is_selected_food && $is_selected_movies should be only this true.

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Thank you very much for your feedback.
    Your code works perfect and gives the results you mentioned. However what i need is:

    // If all three options are selected.
    TEXT WILL BE SEND

    // If option Music and option Food are selected.
    TEXT WILL BE SEND

    // If option Music and option Movie are selected.
    TEXT WILL BE SEND

    // If option Movie and option Food are selected.
    TEXT WILL BE SEND

    // If only option Movie is selected.
    TEXT WILL BE SEND

    // If only option Food is selected.
    TEXT WILL BE SEND

    // If only option Music is selected.
    TEXT WILL BE SEND

    The text is irrelevant to the conditions programmatically and dont need to fetch the array $data inside the $message . Just need the conditions for every option of the user.

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Thank you so much for your help ๐Ÿ™‚

    I am sorry if i confused you. The $message information is not related with the $data. Its just an introduction message text, and i don’t really need data from the $data . The text ‘Food is selected’ was just an example. I just need to pass the if statements for each users choice so that i can send with wp_mail the appropriate text accordingly.

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Let me explain i bit better what i actually need to do ๐Ÿ™‚ On BP registration page i have a checkbox that users can check if they wish (optional field and not required).

    Along with his checkbox preference i am sending a welcome email to the user.

    Something like

    function send_welcome_email_to_new_user($user_id) {
    
    		$data = xprofile_get_field_data( 12, $user_id );
    
           
    		$message = sprintf( 'Hello' ) . "<br>"; 
    		if ( statements ) ) {
            $message .= sprintf( 'Music is selected' ) ."<br><br>";
             } elseif ( statements ) ) {
            $message .= sprintf( 'Food is selected' ) ."<br><br>";
             }elseif ( statements ) ) {
            $message .= sprintf( 'Food and music are selected' ) ."<br><br>";
             }
    		
    		
    		
    		$headers = array('Content-Type: text/html; charset=UTF-8'); 
            
            wp_mail($to, $subject, $message,$headers);
            
    		
    
    }
    	
    			
    			add_action( 'bp_core_activated_user', 'send_welcome_email_to_new_user');

    So actually i need the structure that we have been speaking about before ๐Ÿ™‚

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi, thank you for your help ๐Ÿ™‚ This is what happens with elseif statements:

    $data = xprofile_get_field_data( 12, 23, โ€˜commaโ€™);
    
    if ( ! $data ) { echo "No item is selected";}
    
    elseif ( in_array( โ€˜Musicโ€™, $data ) ) { echo "Music is selected";} -> outputs: Music is selected
    
    elseif ( ! array_diff( array( 'Music', 'Movies' ), $data ) ) { echo "Music and Movies are selected";} -> outputs: Music is selected (should output: Music and Movies are selected )
    
    elseif ( ! array_diff( array( 'Music', 'Movies', 'Food' ), $data ) ) { echo "All are selected";}

    -> outputs: Movies is selected (should output: All are selected )

    I will need to have only one output result according to users checks.

    With the previous code with only if statements , i was getting as an output for example:

    if ( ! array_diff( array( 'Music', 'Movies', 'Food' ), $data ) ) { echo "All are selected";}

    -> outputs: Music Movies Food Music is selected Food is selected Movies is selected Music and Movies are selected Music and Food are selected…. (because it was outputting all the if's. Should just output: All are selected )

    I hope this helps

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Now it works, but there is one problem. The output is giving me results for each if that is true.

    So i have tried to set elseif because i would like only one output according to users checks. With elseif i get correct results only for this type of statements.

    if ( in_array( โ€˜Musicโ€™, $data ) ) { // Music is selected.}

    For array_diff statements i get wrong results.

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi, I did something like this. I didn’t use elseif .

    `$data = xprofile_get_field_data( 12, 23, ‘comma’);

    if ( ! $data ) { // No item is selected.}

    if ( in_array( ‘Music’, $data ) ) { // Music is selected.}

    if ( in_array( ‘Music’, ‘Movies’, $data ) ) { // Music and movie is selected.}

    if ( in_array( ‘Music’, ‘Movies’, ‘Food’, $data ) ) { // All is selected.}`

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    Hello Ravi,

    Thank you for your help. I have tried this and it work fine. However when the user ticks 2 out of 3 checkboxes, or all checkboxes. it doesn’t work. Any ideas?

    Regards Lefteris

  • Participant
    Level: Enlightened
    Posts: 71

    I am sorry for the confusion Ravi, yes it gives me a correct result Music , Movies , Food . But how i can create an if statement to see if music is ticked, or if music+food is ticked, or if none is ticked?