I am attempting to add a buy now button in Woocommerce on the product page so there are two buttons:
- add to cart
- buy now (which will add the product to the cart and redirect to checkout)
I still want add to cart to function as usual.
How can I achieve this? Many thanks.
I managed to resolve this by finding this blog post http://samplacette.com/skip-shopping-cart-in-woocommerce/.
If anyone else finds that they are struggling to implement this, this is how I did it (might not be the best solution but it works for me):
I copied the following text into my theme functions.php
And then I modified theme/woocommerce/single-product/add-to-cart/simple.php (make sure you don’t midify the plugin files so make a copy and paste into your theme files into a woocommerce folder) to the following (notice that I had removed my quantity input from my code so if you need it,ensure you rework the code to get it working):
I added another button next to the existing Add to Cart button but separating the form. The blog post mentions that you can add a hyperlink instead but the above worked for me in terms of the way I needed to customise the page (slightly more long winded)
From blog:
I hope the above helps anyone who has a similar problem as I had.
After much searching I was surprised this is not something that is standard.
Here was my solution:
Either use a hook like “woocommerce_single_product_summary”
Or copy the wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php to your child theme like:
wp-content/themes/child-theme/woocommerce/single-product/add-to-cart/simple.php
Edit the file and add the following code where you want the button to appear:
Now the only problem is the button will take you to checkout and add the correct product but without the correct quantity if you changed it so I used js in my custom.js file that is queued in the footer:
You can change the url from:
to:
If you want the button to direct to the cart instead of the checkout page.