Support

Account

Home Forums ACF PRO acf_form – "On Update" action

Solving

acf_form – "On Update" action

  • Hey all,

    So, I have a repeater field which my site users will be able to use on the frontend using acf_form() to add rows to the repeater. This just happens to be a WooCommerce order, but I don’t think that’s relevant

    Form works fine, rows get added etc and saved to the order. Cool.

    Now, one of the fields in the repeater is an email address. Here’s what I’m hoping I can get to happen:

    1. User adds rows to the repeater on the frontend and submits the acf_form()
    2. When the repeater is saved OR updated on the frontend, the email addresses in the email sub field get an email notification (I can format the email myself later), but only the updated rows/fields

    This action needs to be triggered EVERY TIME the form is changed and submitted on the frontend

    Hopefully this is possible

    Here’s kind of what I have from another support post I stumbled on from Google:

    function delegate_form_update($value, $post_id, $field) {
    
    	// only do it to certain custom fields
    	if($field['name'] == 'ticket_alloc') { // ticket_alloc is the name of the repeater
    
    		// get the old (saved) value
    		$old_value = get_field('ticket_alloc', $post_id);
    
    		// get the new (posted) value
    		$new_value = $_POST['acf']['field_63ca95e88557a']; // this is the key of the repeater
    
    		// check if the old value is the same as the new value
    		if($old_value != $new_value) {
    			// Do something if they are different
    		} else {
    			// Do something if they are the same
    		}
    
    	}
    
    	// don't forget to return to be saved in the database
    	return $value;
    
    }
    add_filter('acf/update_value', 'delegate_form_update', 10, 3);

    Can anyone help, or point me in the right direction? @hube2 @acf-support ?

    Thanks

    Mark

  • Ok, slight change to the above function. Think you have to use the order id rather than the post ID:

    function delegate_form_update($value, $order, $field) {
    
    	// only do it to certain custom fields
    	if($field['name'] == 'ticket_alloc') {
    
    		// get the old (saved) value
    		$old_value = get_field('ticket_alloc', $order->get_id());
    
    		// get the new (posted) value
    		$new_value = $_POST['acf']['field_63ca95e88557a'];
    
    		// check if the old value is the same as the new value
    		if($old_value != $new_value) {
    			// Do something if they are different
    		} else {
    			// Do something if they are the same
    		}
    
    	}
    
    	// don't forget to return to be saved in the database
    	return $value;
    
    }
    add_filter('acf/update_value', 'delegate_form_update', 10, 3);
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.