This is the best I've gotten so far, but I'm getting many errors.
Starting with the main issue; it does redirect to the correct url but the page is showing nothing.
Here is what I am attempting: Reference code
Here is my code.
function pre_process_shortcode() {
if (!is_singular()) return;
global $post;
$user = wp_get_current_user();
$product_id = 27;
$product_bought = wc_customer_bought_product( $user->user_email, $user->ID , $product_id );
if (!empty($post->post_content)) {
$regex = get_shortcode_regex();
preg_match_all('/'.$regex.'/',$post->post_content,$matches);
if (!empty($matches[2]) && in_array('protactPage',$matches[2]) && $product_bought && is_user_logged_in()) {
wp_redirect('https://learndigital-mena.com/cart-2/');
exit();
} else {
// login form or redirect to login page
wp_redirect('https://learndigital-mena/my-account/');
exit();
}
}
}
add_action('template_redirect','pre_process_shortcode',1);