Tips and Tricks HQ Support Portal › Forums › Simple PayPal Shopping Cart › Simple Shopping Cart Tweaks › Automatically require users to be logged in?
Tagged: require log in to purchase
- This topic has 4 replies, 3 voices, and was last updated 14 years, 10 months ago by amin007.
-
AuthorPosts
-
December 15, 2009 at 12:55 am #560zzman44Member
Is it possible for when someone clicks “Add to Cart” to be redirected to the login page if theyre not logged in? And once they log in it brings them to the Shopping Cart? Basically to require users to be logged in in order to Add to Cart and then checkout, while still displaying the Add to Cart button to users who aren’t logged in. (I’m kind’ve new to coding, so not sure if this is easy or not possible)
Thanks though, really love this plugin and I hope this can be done.
December 15, 2009 at 7:31 am #16741amin007ParticipantYeah this should be easy to implement. All you gotta do is check if the visitor is logged in when they hit the “Add to Cart” button. If they are logged in then let them process as usual or else redirect them to the Login page.
Search for the following piece of line in the code (this is what gets executed when the button is clicked:
if ($_POST['addcart'])
You will need to add the check for
is_user_logged_in()
inside this if statement block and redirect to the login page if the user is not logged in.December 15, 2009 at 9:13 pm #16742zzman44MemberI’m sorry, I really have almost no idea how to do this. Everywhere I try and add code it is telling me I’ve made a fatal error and it deactivates the plugin on me. Would it be too much trouble if you could add it to my code? I’m fairly certain this is the if block, correct? It’s not that big of a deal, it’s just a personal pet peeve I would have with orders from unregistered users. Thank you very much so if you can!
if ($_POST)
{
$count = 1;
$products = $_SESSION;
if (is_array($products))
{
foreach ($products as $key => $item)
{
if ($item == $_POST)
{
$count += $item;
$item++;
unset($products[$key]);
array_push($products, $item);
}
}
}
else
{
$products = array();
}
if ($count == 1)
{
if (!empty($_POST[$_POST]))
$price = $_POST[$_POST];
else
$price = $_POST;
$product = array(‘name’ => stripslashes($_POST), ‘price’ => $price, ‘quantity’ => $count, ‘shipping’ => $_POST, ‘cartLink’ => $_POST, ‘item_number’ => $_POST);
array_push($products, $product);
}
sort($products);
$_SESSION = $products;
$checkout_url = “http://www.mydomain.com/checkout”;
$redirection_parameter = ‘Location: ‘.$checkout_url;
header($redirection_parameter);
exit;
}
January 26, 2010 at 3:00 am #16743joanMemberHi Ruhul
As always you are doing a fantastic job with Simple Paypal. I was wondering if the above ‘require login’ could be built on so that the users name is passed to Paypal’s form ?
Regards, Joan
January 26, 2010 at 6:00 am #16744amin007ParticipantI can give you some guidance on how to include the username but I don’t plan to add this to the shopping car cause it falls under the responsibility of a membership plugin.
-
AuthorPosts
- You must be logged in to reply to this topic.