Pass form value to ccaps field on registration

Hi Guys,

I’m looking to populate my customers ccaps field with data they’ve chosen from a dropdown. There are three values they can choose. I’ve got as far as adding this custom function to my child themes functions.php file.

My custom field is called ‘fund’- I feel like I’m pretty close, but I can’t seem to get this working…Can anyone shed any light?

add_filter ("ws_plugin__s2member_pro_paypal_sp_checkout_post_attr", "my_paypal_pro_sp_checkout_form_attr");
function my_paypal_pro_sp_checkout_form_attr ($attr = array ())
    {
        if ($_POST["fund"] === "american")
            {
                $attr["ccaps"] = "american"; 
            }
        elseif ($_POST["fund"] === "chinese")
            {
                $attr["ccaps"] = "chinese"; 
            }
        elseif ($_POST["fund"] === "both")
            {
                $attr["ccaps"] = "spanish,chinese";
            }
        /**/
        return (array)$attr;
    }

Have you tried using == instead of ===?

Maybe you must check for “funds”?
Also, it’s good to check what exactly returns your function, and how far it works.

I’ve tried this, unfortunately it’s still not working. I checked what was being returned via the console too and can see that it’s returning ‘american’ http://d.pr/i/wShV so I’ve updated my code above to reflect this, it’s still not working.

@krumch - I’ve updated my post, my field was called ‘fund’, excuse the typo :slight_smile:

1 Like

To close this post (as I often find so many development posts that never actually have a resolution) I’d like to point out I was using the wrong filter for the form.

The filter I needed was:
ws_plugin__s2member_pro_paypal_registration_post_attr

and not
ws_plugin__s2member_pro_paypal_sp_checkout_post_attr

You can find all S2Member filters here:
https://www.s2member.com/codex/stable/s2member/paypal/package-filters/