
Ok guys here is a revised Login feature I have conjured up. Sorry if it took me forever to post this as I was extremely busy with other projects. Before we start let’s go over what this feature does.
Assuming “Required registration to checkout is active”.
It displays a login section on top for customers who already has an account. It is ajaxified meaning it will run dynamically without page load. And if you type in your credentials, it will check in the background if your credentials are valid and display error otherwise. This is all within the same page without it going to the mysterious WP login page which could freak customers out. It also provides a link at the bottom incase you forgot your password. But this link WILL take you to the WP login however if you display your logo instead of the WP one, it makes it better.
What does the default WPEC checkout page do? Well the default doesn’t even show the login section on top thus existing members would not be able to login. So every time they checkout they would have to register over and over again. This feature fixes all of that problem.
On with the code…
First put this snippet of code inside your checkout template. If you’re using the default, then create a separate checkout template and select it as a default in the page edit in the backend. After you have opened up the checkout template php file, just before the “Loop” insert this snippet.
CODE:
<?php if ( is_user_logged_in() ) : ?> <p>(Hi, <?php echo $current_user->user_login; ?>)</p> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out</a><br /><br /> <?php endif; ?>
The top code snippet basically just checks to see if the user is already logged in and if so, say hi and show a logout link.
Then go to the WordPress plugins URL and download a plugin called sidebar-login. Upload it to your plugins folder and activate it…
In the settings, leave everything blank.
Then open up shopping_cart_page.php in your WPEC themes folder and after this block of code:
CODE:
<?php global $wpsc_cart, $wpdb, $wpsc_checkout, $wpsc_gateway, $wpsc_coupons; $wpsc_checkout = new wpsc_checkout(); $wpsc_gateway = new wpsc_gateways(); $wpsc_coupons = new wpsc_coupons($_SESSION['coupon_numbers']); //echo "<pre>".print_r($wpsc_cart,true).""; // echo "<pre>".print_r($wpsc_cart,true)."</pre>"; if(wpsc_cart_item_count() > 0) : ?>
Insert the following:
CODE:
<?php if (!is_user_logged_in()) : ?>
<p>If you are an existing member, you can login below for faster check out, automatic filling of billing/delivery details and check your purchase history.</p>
<?php sidebarlogin(); ?>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">Recover password</a><br /><br />
<?php endif; ?>
The above code says if user is not logged in, show the login fields and a link to recover password. If logged in, show nothing.
That is it…Now you can copy the first code snippet I had you insert to the checkout.php template to the “your-account” template as you will want to give customers a way to login on that page.
Hope this is helpful to someone…



Awesome idea. Thanks for the tip!
I read a comment at: http://getshopped.org/forums/topic.php?id=14158 that said you have a solution to make a variation a checkbox instead of a drop down. Is this a simple fix?
Thanks.
Hi Jacob,
Unfortunately no it is not a super easy fix and will require some time.
You are a star! Seems a strange floor in the plugin not to have this functionality in the first place
Yes I agree, it should have been implemented in the first place. But stay tuned because I have an update for this script…
Do you have the update for the script yet? I need to make these changes on my website and was hoping to use the latest script. Thanks!
Will definitely update when I get a chance..
Hi, Sounds great, but I am missing something.
You state: After you have opened up the checkout template php file, just before the “Loop” insert this snippet.
I can’t find the file you mention. (must be me ; ))
Just using the default shop theme.
If you can point me to the right direction, I would be most happy.
You have to create a custom template for that page. Have a look on the WordPress Codex and search for custom page template. It will show you have to create one if you don’t already know.
Hmm, I tried to understand how to create my own custom template.
I failed ; )
I copied the “user-log.php” file and added your code snippet, (on top of all other code, hope that that is OK).
If I understand well I have to link to that .php file in one of the visible pages.
Since the original page uses a shortcode I wasn’t exactly surehow to do that correct.
That’s just me, not understanding what I am doing (not a programmer by any means.)
If someone feels like explaining on noob level, please do ; ).
The template has nothing to do with WPEC, its a WP thing. So I suggest to look on the WP Codex as it shows you exactly what to do. If you still don’t understand, I would suggest hiring a professional to implement this for you.
Hi there, just wondering how this will autofill the customers billing fields, unfortunately this isn’t happening even though they are logged in and have previously filled out billing details.
thanks.
Carly
Hi Carly,
WPEC plugin is responsible for the detail of the logged in user not the script I provided. But at the time I wrote that tutorial, it was working. I am assuming the later versions broke that functionality. Are you also using the latest version of WPEC?
Hi,
First, thanks for all your posts. some of them already helped me a lot!
I’ve read the “create a custom template page” but I still haven’t really figured out where should i insert your code.
Can you point me out in the right direction?
Tks. G
Hi Goncalo,
Have you already created a custom template page for checkout and selected it on the checkout page in the backend?
I’ve created a custom template and called it checkout.php per ur instructions. how do you select it in the backend?
Have a read here.
http://codex.wordpress.org/Pages#What_Template_is_used_to_Display_a_Particular_Page.3F
Yes, that is the page I referred to in the first place when figuring out how to create the checkout php file. I still do not understand what you mean by selecting it in the backend.
On that same page it shows you how to select it. In your WP page edit, you can change the template it uses.
Hi Roy,
I’m sorry, but I am still confused and pointing me towards the same page doesn’t clarify anything. The confusion is mainly with the checkout.php file – is it just a file with the code written above or something more? Where exactly is the loop for the checkout.php file? What is the exact name of the checkout template file? And where should I place it (i.e. which folder)? Could you possible post it on this website so we could understand better?
Thanks,
Donna
Donna,
It seems you don’t have a very strong grasp of how WP works. This article was intended for people who have at least a working understanding of the structure. With that said, it would be very time consuming for me to write every single detail here. This was meant to give you an idea of how it could work.
The codex page shows everything needed prior to putting my code. You just have to read it very carefully from top to bottom. If any terms that are not familiar to you like “the loop”, type it in the search of the codex and it will show you what that is. These are all WP terms and should be understood prior to doing customized WP work.
Sorry I couldn’t be of more help…
Thanks a million – this worked perfectly.
Hi Marie,
You’re welcome!
Hello. Thanks for the code. I can’t seem to get it to work. I am using version:3.7.6.9. I get the following error:
“Fatal error: Call to undefined function sidebarlogin() in C:\xampp\htdocs\wordpress\wp-content\plugins\wp-e-commerce\themes\Pworks\shopping_cart_page.php on line 11″
I searched for the sidebbarlogin function and I can’t find it.
Your help is much appreciated.
Hi Izzy,
It seems you have not downloaded the plugin and activated it.
like some of the others, I am stuck on how to create a custom template. This is not very clear. Neither you nor the codex mention if the whole code from the checkout page is copied into the custom template, or not, and where the actual code for the checkout page is to begin with. I know you suggested outsourcing this, but no one else seems to be very clear either. This is obviously an easy solution for you and some others, so I’m not sure what I’ve missed. I’d really appreciate it if you could offer a little more detail. Thanks so much.
No, WPEC and WP pages has nothing to do with each other. So you don’t copy the whole code from your checkout page. The Codex should have been very clear on how to create custom templates. You can duplicate the page.php and rename it to checkout.php and change the template name inside the file and then you apply the changes I’ve mentioned in the post.
Brilliant. it was this page.php clue that I had missed. This detail of taking page.php and making that the template, that was where I was stuck. Thankyou
Hello.
First I want to thank you for this feature. I am using wp-ecommerce 3.7.7 with wordpress 3.0.1. Well my problem is this:
This version of wp-ecommerce provides in the checkout page a login form, however I implement your version of login in the checkout page. I also created a custom checkout template. Nevermind, when i place an order from my computer i fill the personal information and shipping details. When i log-in from a different computer with the same username and password (of course
), to place another order, those details aren’t there. I can’t find the solution for this problem.
The web adress is http://www.webacademy.ro/colportaj
I look forward to hear from you!
Hi mihaiteo,
Unfortunately this is a feature of WPEC and does not have anything to do with the code I’ve shown. But I do remember it working with older versions of WPEC when I created this tutorial.
Hey Roy.
I know that my question wasn’t related to your topic, but i asked you because no one on the getshopped.org forum respond.
Anyways thanks for the post, and if you have any idea with my problem i would be grateful.
Best regards!
Hello Roy,
Thankyou for your help.
unfortunately my site is built in Thesis so there is no page.php page. Which is also why I have been chasing my tail. I have created a custom Thesis page, created a hook in the custom_functions.php page. Do you know, should your script work the same way in this custom_functions.php file? ie. the snippet before the loop?
I was wondering if you would mind just giving me a hint to indicate if the code below looks right to you or where it’s wrong? I am really trying to get this login solution to work. Can I pay you to implement it for me?
Thanks.
//custom page template————————————————-
function isabellas_custom_function(){ // YOU CAN NAME THIS FUNCTION ANYTHING, but it must match the name on line 108
if (is_page(‘checkout’)) //IMPORTANT———-INSERT CORRECT PAGE NAME HERE
echo “\t\t\n\n”;
thesis_hook_before_content(); #hook
if ( is_user_logged_in() ) : ?>
(Hi, user_login; ?>)
<a href="” title=”Log out of this account”>Log out
<?php
$loop = new thesis_loop(); // HERE'S WHERE THE LOOP STARTS
thesis_hook_after_content(); #hook
echo "\t\t\n\n”;
thesis_sidebars();
}
remove_action(‘thesis_hook_custom_template’, ‘thesis_custom_template_sample’);
add_action(‘thesis_hook_custom_template’, ‘isabellas_custom_function’); //IMPORTANT!! — same function name from line 91 here
//—— UPLOAD THIS FILE AND SELECT Custom Template from the drop down on the Edit Page page.
//end custom page template———————————————-
?>
Yes you should be able to implement this on Thesis the same way but with a bit more fiddling around as Thesis is a nightmare for developers.
The code proposed in this post is incomplete. $current_user will be an empty variable unless you do this:
$current_user = wp_get_current_user();
.. right after if ( is_user_logged_in() ) : .
No, that is not true because $current_user has already been assigned elsewhere and you can freely use it. Try it for yourself and see…
$current_user was null here until I added $current_user = wp_get_current_user();
Admittedly, global $current_user works too. That wasn’t anywhere in my shopping_cart_page.php until now. But thanks, that’s easier than re-retrieving it.
Normally yes I would agree that a created variable not assigned anything would be null but in this case, it has been assigned globally. So if you put that snippet of code anywhere in WP and logged in, you will see that it does pull out the current logged in user name.
And I’m telling you it doesn’t return anything in shopping_cart_page.php until I either make it global there, or re-retrieve it.
I’ve seen before in PHP that it’s necessary to redeclare a variable as global in a template file before you can access it.
Right I heard you and is the first time I’ve heard this…it works perfectly fine on my end without re-declaring it. No one has yet to tell me it doesn’t pull the user name out…strange…
Hey, I have the same problem.. WP 3.1.2 – the soultion from Joris is working though.
can i just say that its amazing how much you respond to your comments? kudos for that my friend.
I must admit that many of peoples frustrations are with wpec and not with you I think. Most of us are not hard core php developers and really rely on copy, paste and modify to get most of our work done…
i wish that i could have the form auto-populate from the user data. I wonder why this is not happening anymore in the current version of wpec. What version are you running where it does work?
Hey Paul,
Yeah I provided this code back several versions ago and it used to work as you described. I have recently heard it didn’t work anymore as well. I have seen post on getshopped.org forum that has a solution for this though. But if you really think about it, it isn’t that hard to populate the fields on login. Perhaps I should write a tutorial to do so…
if you write a good tutorial, then I will be looking for your paypal donate button…
the forums are frustrating to scour through.. seems like someone needs to do a wpec roundup of tips and tutorials from the forum.
Yeah I’ve started and paused on a roundup post as I got busy during the process but it is coming along…
hi roy, like many other users, i too cannot find a way to have the checkout fields auto-populate and was wondering of you could point me in the right direction as to where i can find the instructions on how to do this. thus far i haven’t had any luck in the forums.
thanks again for all your knowledge and support!
r
I believe I replied to you on the forums..check there…
Hi Roy,
I just noticed there seems to be a problem when I have the Login With AJAX widget active on the right sidebar, it basically does not allow the checkout page login form (created as per your specifications) to recognize the user login credentials and generates an error message saying something like ‘invalid user name and password’. Is anyone having the same problem and/or found a solution to allow both the sidebar widget and checkout page form?
Tnx,
R
Hi Ricky,
Unfortunately I don’t have the time to look into this right now, perhaps posting it on the forums?
Hello Roy, great article and a big thanks for doing this – really shocked WPEC doesn’t come with this?!
I’ve yet to try this feature on the latest version of WPEC, do you know if it still works and is safe/stable to use or will you require a code update?
@Ed – Unfortunately this is for the older 3.7 series of WPEC and the code is not the same.
Thanks for the swift reply Roy. I’m still amazed at how poor the WPEC user/account features appear to be!