Client would like the checkout page to load after clicking “Add to Cart.” Is that possible?

Yes, it is.
In the wpsc page templates single_product.php, products_page.php, list_view.php and grid_view.php find this line :

<form class='product_form' enctype="multipart/form-data" action="<?php echo wpsc_this_page_url(); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>">

change the action so this line looks like:

<form class='product_form' enctype="multipart/form-data" action="<?php echo get_option('shopping_cart_url'); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>">

Basically what we’ve done here is made the form direct to the shopping cart page, but the ajax call will stop this from ever running, so we have to disable the ajax call, so

In js/user.js around line 93
find this line:

if(file_upload_elements.length > 0) {

and change it to :

if(file_upload_elements.length > 0 || true) {

This line of js usually only triggers if your buyers have a file to upload, since the file cant be uploaded through ajax wp-e-commerce refreshs the page, so we will just piggy back on this and make the condition trigger every time by adding OR true.

Now refresh your page and when you click add to cart you should be directed to the checkout page!

Happy e-commercing~
SCM

22 Responses to “Client would like the checkout page to load after clicking “Add to Cart.” Is that possible?”

  1. Thanks for this, exactly what I’m looking for. However, the ajax code does not exist in the latest version, so is there another way to block that ajax code?

  2. Hi Jeremy what version are you talking about it exists in all 3.7 versions. This code is based on wp-e-commerce 3.7.5.3 and I know it will work in 3.7.6 betas and the band spanking 3.7.6rc1

    best
    Jeff

  3. Hey Jeff, I dont see this line of js either.. Im running Version 3.7.5.3

  4. Ok I just checked and I got the wrong file name sorry guys! You were right I was wrong :( it’s in wp-e-commerce.js
    :0

  5. hehe cheers man, works sweet now.

  6. Hi Jeff,

    This would be a great example as a Plugin for WP e-Commerce that adds a radio option list to the Store > Settings > Presentation page.

    x Show popup prompt | o Go straight to Checkout

    You would need to move the altered snippet mentioned above out of wp-ecommerce.js and into a dynamic file that the Plugin can interact with I assume. Thoughts?

  7. Hi there,

    can someone suggest the code i would need to have a button to do thi? Like a buy now button that I can insert on a page that has a fixed price description etc and goes straight to the checkout?

    Just looking for a buy it now button code :)

    Ta
    Amber

  8. Hi I’m unable to take on anymore work at the moment so I would suggest talking to a developer from the getshopped/wp-consultants page to create a new shortcode that does this for you,, I think you have a great idea, I would suggest the make it into a module or plugin then integrate it to core with the help of the instinct developers.

    Est
    Jeff

  9. This is actually not working for me. It was working before I updated. Thank goodness I did a back up before I updated the e-commerce. When I put everything back the way it was everything was working fine, except for this.

    I have the first codes action set to but when I view the source code, it doesn’t have the shopping cart url, it has the single product page url.

    The site can be found here: http://www.justblahsome.com

  10. check your single_product.php in your selected theme… i believe you dont have the get_option in the form (did you not move your themes to a safe place before upgrading?) I’m willing to bet a sunny day that you don’t have that code right….

  11. Actually, I do have it set as get_option(’shopping_cart_url’); but for some reason when I view the source it’s pulling the single product page url instead of the shopping cart. I changed the single_product.php file and ftp’d it to the server. When that didn’t work, I used my file manager to try and change it there but the change is already there. Also tried clearing my cache and using different browsers. Nothing. It’s very odd.

  12. Well it is raining here,, so I guess I did loose the bet… BUT are you 100% sure you are editting the correct theme file? I know lots of ppl get confused since the fiels are everywhere, but please check the path in Settings>Presentation on the right hand side there is a box that tells you where the folder the theme files is located,,, are you SURE you are editting the single_product.php there? cause if you aren’t and the files are there,,, your changes have been in vain…

  13. Yup. I’m positive I am editing the right theme. I even deleted the whole shopping cart and uploaded the original one, made the changes and it’s still not directing me to the shopping cart page. I have been having only two issues with the shopping cart now. The products are not separating into categories as well.

  14. Sorry, fixed the categories issue.

  15. Hey, just want to say that this is a great fix and it works perfectly for me.

    Thanks!

  16. How do you do this in Version 3.7.6.4?

  17. Great Solution but there are 2 issues:

    1. if the item is out of stock it still takes the customer to the checkout and gives a message that there are no products in the shopping cart and it looks like a bug to the customer.
    is there a workaround for that??????????

    2. every time you update the WP e-commerce plugin, you need to go to the js file and change the code again.

  18. I believe it’s the same,,

  19. Hi yes those are two very valid draw backs and for every solution there are pros and cons, the pros on this system is it is a quick fix (for the code savvy) and the two cons you provide:
    1. Yes that is true, and you could go and write a hefty piece of code to do an Ajax check to see whether the product is in stock, and provide the user with feed back (personally if that was the case I’d just turn on fancy notifications from settings>presentation !! )
    2. You could probably do a plugin and deregister the js from running, but I’m not savvy enough (or interested enough to do such a thing at the moment as I am busying myself with 3.8 and new releases for gold modules)

    Best
    Jeff

  20. I’m running this fix on a test store and noticed that when I add a product to cart and land on the checkout page, if I refresh that page it automatically adds another item to the cart. Not a huge deal since I don’t know how many customers will refresh the checkout page, but they would probably be upset if it automatically added more products to their order that they didn’t want.

  21. Thanks so much for the tutorial!

    One question – I changed the code, so now it looks like

    The mystery thought is that it redirects to the product page, not checkout page. My client is using version 3.7.6.5 of the plugin. Do you know if the code for the Checkout page has changed from shopping_cart_url to something else?

    Thanks again for your help!

    Andrew

  22. Well that’s just a limitation of form posts I don’t think there would be any easy fix for that,, if you are worried however I’d just recommend turning on fancy notification and not implementing the above fix ;)

Leave a Reply