Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter lancer85

    (@lancer85)

    @cpvb86 Yes I can, however the trigger on “personal_options_update” didn’t quite trigger as I expected. There were some finicky processes that didn’t pan out as I expected. I will upload that code later today.

    Thanks!

    • This reply was modified 4 years ago by lancer85.
    Thread Starter lancer85

    (@lancer85)

    No, It’s now turned on but nothing renders to the email.

    Thread Starter lancer85

    (@lancer85)

    Hey Kuba,

    I think I might have figured it out. For this one instance… still having issues with the merge tags, however, I was able to successfully trigger the user meta change by using the action hook “personal_options_update”. Which once the add_therapist AJAX call is complete the email is sent. I was able to go in and change the therapist and another email was sent. So, I am excited that worked! Just need to understand why I can’t get the merge tags not to render on the email side.

    Thread Starter lancer85

    (@lancer85)

    Hey Kuba,

    I was able to successfully get the trigger to happen on “update_user_meta” but the issue is that it fires each time the page reloads. I tried “profile_update” but according to WP docs this only fires when the user profile has been updated. Since this is user meta, the profile isn’t being updated, just the meta field.

    So after further investigation, I need to use an action hook that detects the change for the meta that is being changed from ‘add_therapist’ function.

    This is that function

    add_action( 'wp_ajax_nopriv_add_therapist', 'add_therapist' );
    add_action( 'wp_ajax_add_therapist', 'add_therapist' );
    
    function add_therapist(){
      $user_id = $_REQUEST['user'];
      $therapist_id = $_REQUEST['therapist'];
      update_user_meta($user_id, 'has_selected_therapist', 1);
      update_user_meta($user_id, 'selected_therapist_id', $therapist_id);
      update_user_meta($user_id, 'selected_therapist_status', 'Pending');
    
      echo 'Therapist has been selected';
      die();
    
    }

    So essentially, I need to get the trigger to fire when update_user_meta(‘has_selected_therapist’) has been changed (to the 1). Is there anything I hook to that would work with the trigger??

    Additionally, I am turned on background processing, and I am still not seeing the User First Name and Last Name rendering.

    Here is that code:

    add_action( 'notification/elements', function() {
    
    	class TherapistSelected extends \BracketSpace\Notification\Abstracts\Trigger {
    
    		public function __construct() {
    	
    				// Add slug and the title.
    				parent::__construct(
    						'therapistselected',
    						__( 'Therapist Selected Message', 'therapistselected' )
    				);
    	
    				// Hook to the action.
    				$this->add_action( 'update_user_meta', 'add_therapist' );
    	
    		}
    	
    		public function merge_tags() {
    			
    		$this->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\User\UserFirstName() );
    		$this->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\User\UserLastName() );
    		$this->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\User\UserEmail() );
    		
    	}
    
    	
    	}
    
    	notification_register_trigger( new TherapistSelected() );
    } );

    Let me know if you see anything missing from this, or if there is a way to configure this better.

    Thanks!

    Thread Starter lancer85

    (@lancer85)

    Ok, I will give that a try. If I continue to have an issue, I’ll let you know what issue I am facing and see if you can further assist. Thanks for your help thus far.

    Thread Starter lancer85

    (@lancer85)

    That is correct. The merge tags show up in the side bar, but the value isn’t rendered on the email notification.

    Could you provide an example of how to trigger an email on a meta field change?

    My example is when a user chooses a therapist, I need to trigger an email to that therapist. I have two meta fields that change, one that changes from false to true “has_selected_therapist” and the other is “selected_therapist_id”

    I am trying to create this notification for a therapist to be alerted when a user has selected them

    Thread Starter lancer85

    (@lancer85)

    Disregard, after further review, the version of ACF wasn’t compatible with the version of ACF Image Crop.

    Thank you for your time.

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