I am having a page where there is a button named buy.While clicking the buy button its suppose to goto buy page if the user is logged in or to login page if the user is not logged in. I am trying to implement this using “is_user_logged_in()”. I have tried “header:location” which gives me a warning since i have written for get_header() initially. i have tried it using javascript but nothing seems to work.here is my code please help me.


function myfunction() {

function redirect() {
    <?php if(!is_user_logged_in()){
    <?php }


<form action="" method="post">
<input type="submit" name="delete" value="Delete" class="btn btn-primary" id="show" onclick="myfunction()">
<input type="submit" name="buy" value="Buy Now" class="btn btn-primary" onclick="redirect()">


Read more here: How to redirect to "login page" or "buy page" depending on user login status


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: