Adding a “Buy Now” Button with WooCommerce

Adding a Buy Now button with WooCommerce is pretty easy, so I’ll keep it short. All you need to know for a direct Buy Now button is:

<?php echo do_shortcode('[add_to_cart_url id="25"]'); ?>

The above outputs the URL to add the item to the cart. I found that this didn’t work very well if you had “Enable AJAX add to cart buttons on archives” checked. In WooCommerce -> Settings -> Catalog, it’s under the “Add To Cart” section.

I’m sure there’s a way around it with some JavaScript or a further look but I’ve done neither so far.

My full code looks like this:

<?php $add_to_cart = do_shortcode('[add_to_cart_url id="25"]'); ?>
<a href="'. $add_to_cart .'"><img src="'. get_template_directory_uri() . '/img/small-cart.png" />Buy Now</a>

The button includes a cart icon to make it super sexy, or basic, however you see it. WooCommerce also has a large list of shortcodes to make developing e-comm themes easy. To see all of their shortcodes, click here.

Reasoning

So why bother with a “Buy Now” button. For me at least it’s nice and direct. So someone sees Buy Now and that’ the exact action that they’re able to take. They head directly to the checkout process to buy the thing they are trying to purchase.

By reducing steps in between, the hope is that conversion rates become higher. Without analytics it would be tough to know for sure, but that’s the hope.

Subscribe
Notify of
guest
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Patrick Morgan
Patrick Morgan
6 years ago

Hi. Thanks for this nifty bit of code! I was able to wrap this up in a widget and create a sticky “add-to-cart” button, something I’ve been trying to do for ages!!

I do have one question though – surely this will only work as a “buy now” button if you have Woocommerce set up to always redirect people to the cart after they add something?? We do not currently have this setup. Do you know if there’s a way to generate a URL which will add the product to the cart and then re-direct to the the cart after??

Many thank 🙂

Mindaugas Vaiciunas
Mindaugas Vaiciunas
5 years ago

Hi. Sorry for my beginners question. Where do I paste this code?

PK Peter
PK Peter
2 years ago

I would like this to be answered. I am stuck.

JB
JB
5 years ago

Hey, Even I want to know where to paste this code ? I want to have Buy button along with all products.

Themefisher
5 years ago

hello ,
This code doesn’t work. may be woocommerce changed their shortcodes.
Thanks

graham
graham
5 years ago

I also would love to know where it should go to achieve a buynow button beside the addto cart button

ste
ste
5 years ago

Hello, you can use an excellent and very useful plugin to do this, the plugin is called “WooCommerce Quick Buy”, it’s free. 🙂

Link: https://wordpress.org/support/view/plugin-reviews/woocommerce-quick-buy

Neil Bannet
3 years ago

Thanks

John Hartley is a Director of Product Engineering at Beam Dental in Columbus, OH. With 5+ years of leadership experience he has worked in startups, agencies, and began his career as a freelance Front End Developer. Always looking to iterate, this blog is a place for him to share his knowledge as well as hone his craft, challenge assumptions, and build a strong base of leadership and management knowledge. Connect with him on LinkedIn

8
0
Would love your thoughts, please comment.x
()
x