custom publishing types: CPT dynamic link structure based on the value of the ACF field

There are already some questions on this subject, but they are not helping my problem. So, what I want to achieve is a CPT dynamic link structure based on the ACF (radio) value.

// _cb means check box
radio_acf_cb = foo
radio_acf_cb = bar

Depending on the user's choice, the permanent link would look like this.

// fixed_word is the first part of the permanent link that will be static
// foo / bar are the values ​​based on the choice of ACF
// 123 is the ID of the publication

example.com/fixed_word/foo/123 // if you choose foo
example.com/fixed_word/foo/123 // if the bar is chosen

This is what I tried so far:

add_filter (& # 39; post_type_link & # 39 ;, & # 39; so51217355_post_type_link & # 39 ;, 10, 2);

function so51217355_post_type_link ($ permalink, $ post) {

if (& # 39; my_cpt & # 39; === $ post-> post_type) {

$ choice = get_field (& # 39; foo_bar & # 39 ;, $ post-> ID) // foo or bar

$ choice_slug = $ choice == & # 39; foo & # 39 ;? $ choce: & # 39; bar & # 39 ;;


if ($ choice_slug) {
// This would give me example.com/fixed_word/foo/123
// or example.com/fixed_word/bar/123
$ permalink = & # 39; / fixed_word / & # 39 ;. $ choice_slug. $ post-> ID;
}

}

returns $ permalink;
}

Now I know that I need to write some custom rewrite rule with add_rewrite_rule () but I'm not sure how to set the conditions.