Tips and Tricks HQ Support

Support site for Tips and Tricks HQ premium products

  • Home
  • Contact Us
  • Documentation
  • Forum Home
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration

Automatically require users to be logged in?

by

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 15 years, 3 months ago by amin007.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • December 15, 2009 at 12:55 am #560
    zzman44
    Member

    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 #16741
    amin007
    Participant

    Yeah 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 #16742
    zzman44
    Member

    I’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 #16743
    joan
    Member

    Hi 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 #16744
    amin007
    Participant

    I 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.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

Forum Related

  • Forum Home
  • Forum Search
  • Forum Registration
  • Forum Login

Support Related Forms

  • Contact Us
  • Customer Support
  • Request a Plugin Update
  • Request Fresh Download Links

Useful Links

  • Plugin Upgrade Instructions
  • WP eStore Documentation
  • WP eMember Documentation
  • WP Affiliate Platform Documentation
  • Tips and Tricks HQ Home Page
  • Our Projects

Quick Setup Video Tutorials

  • WP eStore Video Tutorial
  • WP eMember Video Tutorial
  • WP Affiliate Platform Video Tutorial
  • Lightbox Ultimate Video Tutorial

Our Other Plugins

  • WP Express Checkout
  • Stripe Payments Plugin
  • Simple Shopping Cart Plugin
  • Simple Download Monitor

Copyright © 2025 | Tips and Tricks HQ