Custom Capabilities and different Redirect Pages

I have two different custom capabilities (2 products sold) and if someone doesn’t have access I want it to redirect to two different pages when they try to access the product (the sales page for each one)

So, I currently have this in functions.php

add_action (“wp”, “my_custom_capabilities”);

function my_custom_capabilities()
{
if(has_tag(“sps_porter”) && !current_user_can (“access_s2member_ccap_sps_porter”))
{
header ("Location: Location: https://mydomain/sales-pg-1);
EXIT ();
}
else if(has_tag(“tbr”) && !current_user_can (“access_s2member_ccap_tbr”))
{
header (“Location: https://mydomain/sales-page-2”);
EXIT ();
}
}

The problem is that no matter which blocked page they try to access it simply takes them to the membership options page in the general settings

This is a theme issue not a s2member issue. Talk to your theme support.

When you call the PHP function Header() you need to remember the following:

Remember that header() must be called before any actual output is sent

You need to either override the theme’s header.php file using a version customised to output the redirect in the HTML head or use a theme provided hook to inject Head information.

An alternative is to make this into a custom shortcode that you place at the top of the S2Member membershp options page that outputs a different javascript redirect statement for the different conditions.

See https://www.w3schools.com/howto/howto_js_redirect_webpage.asp