Support

Account

Forum Replies Created

  • @hube2 Hey, I think I’m missing something, because this isn’t sending the email:

    
    function delegate_form_update($value, $post_id, $field) {
    
    	$order = new WC_Order($post_id);
    
    	// global email settings
    	$to = get_option('admin_email');
    	$headers = array('Content-Type: text/html; charset=UTF-8');
    
    	// this will hold the number of rows - old value
    	$old_rows = intval(get_post_meta($order, 'ticket_alloc', true));
    
    	// count the rows submitted
    	$new_rows = count($_POST['acf']['field_63ca95e88557a']); // field key of repeater
    
    	if($old_rows != $new_rows) {
    		// number of rows has changed		
    		$subject = 'Number of rows has changed';
    		$body = 'This is the mail body';
    		wp_mail($to, $subject, $body, $headers);
    	}
    
    	return $value;
    
    }
    add_filter('acf/update_field/key=field_63ca95e88557a', 'delegate_form_update', 10, 1);
    
  • @hube2 Ahhhhhhh ok, so compare each row individually rather than compare the parent repeater

    I’ll give it bash and come back to you (if that’s ok) with a yay or nay

    Appreciate the help

  • @hube2 Ok that makes sense, thanks for that

    Now, how do I check if any of the get_sub_fields() have been changed/updated?

    Eg. 4 rows have been previously saved. User edits one/many of those fields and saves again

    Or was my initial code correct for checking that?

  • 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 4 posts - 1 through 4 (of 4 total)