Try this –
Add your button inside a form and write down script to add product to the cart and redirect user directly to the checkout page. Suppose, following is the button that you can put on single product page using a WooCommerce hook.
<button name="checkout_now"> Checkout Now </button>
PHP code:
global $woocommerce;
$post_id = get_the_ID(); //you can directly use get_the_ID() as you are on single product page or you can also make use of global $product object and then $product->ID
if( isset($_POST['checkout_now']) ){ //assuming the form method is 'post'
$woocommerce->cart->add_to_cart( $post_id );
$checkout_url = $woocommerce->cart->get_checkout_url();
wp_redirect($checkout_url);
exit;
}
Related Posts:
- How to correctly add Javascript in functions.php
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Woocommerce: How to override core functions in functions.php?
- Get WooCommerce shipping methods programmatically
- Add a custom text field to WooCommerce admin product data “Variations”
- Translating add to cart woocommerce button [closed]
- Add attribute / custom attribute to product in woocommerce
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- Help with some php math in WordPress
- How do I display a user’s previous orders as a select box option on a product?
- combine Code 1 with Code 2
- Adding nofollow to a PHP generated Nav
- Automated Cart Update With Alert Box Each Time
- Two Different Links for Same Product – WooCommerce [closed]
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Show prices with tax in Woocommerce Mini Cart [closed]
- Problem with custom plugin using AJAX to pull info from php file
- Reload part of checkout on changed shipping method
- How to get all shipping rates and costs without session in woocommerce?
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- Trying to build simple deposit code that hooks into woocommerce
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- how to fix error “called incorrectly, should not be accessed directly”?
- Function works when I don’t login to WordPress but when I login then it doesn’t work
- How to auto fetch customer details in Woocommerce in checkout page
- How to make products with no cost in WooCommerce
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Validation algorithm in checkout field
- How to remove coupon dropdown feature
- Add html link in functions.php files of the theme
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- Seo Friendly Filter URLs
- how can i add class or span tag at sprintf?
- Display attribute on shop page after the title
- WooCommerce – Moving Product Price to the Left of Add to Cart Button [closed]
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Have Woocommerce show product price if id, when not logged in
- WordPress site with embedded menu – gives You don’t have permission to access /wp-content/themes/xxx/taxonomy-redirect.php on this server
- How to separate product payment and shipping payment in WooCommerce checkout? [closed]
- Output product category link from WP_Query
- How to get woocommerce orders with get_posts method in a shortcode
- Variation prices breakdown only for single product page
- Woocommerce disable order item link (backend) [closed]
- Set all WooCommerce Products to Simple, Virtual & Downloadable
- Undefined array key 0 wp-includes/capabilities.php on line 76
- How do I know if the user is a customer?
- Change the URL of an image from wp_get_attachment_image_src for Product Posts based on Category
- Combine change Email WordPress and woocommerce emails template
- I want to fusion the product columns in email table order
- WooCommerce is_product_category() not working
- Woocommerce Product page add on checkbox and price
- How to set Nav as a default menu in wordpress
- Best way to use variables in multiple functions?
- Display all categories including sub categories under a list ul
- How do I programmatically add ‘reviews_allowed’ to WooCommerce product?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Get product price in a different currency using WooCommerce Currency Switcher
- Discount in the specific product title using keyword ( Woocoommerce )
- Place product field value as variable in php
- Adding product permalink on admin order page throwing error
- How to override WooCommerce Order Item Meta with data from Cart?
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Add custom attribute to product’s HTML to woocommerce cart page
- Change WooCommerce template for PDF – access to custom field
- How can i style “echo apply_filters”
- Get all woocommerce product names with price and show using core php
- Add custom ID attribute to all woocommerce products on archive pages
- Put a span class in the shortened product title
- How to properly create multiple conditions to redirect users roles to different pages
- How can i put php code on the wordpress page?
- Sort WooCommerce data with WP-CRON?
- Display specific main Sub Nav on Woocommerce product pages
- How to detect if a revision was made by woocommerce or wordpress?
- Need Quick Help With Product Category Page
- How do I prevent a folder from reappearing in my home directory?
- jQuery doesn’t work in my php snippet
- Use WP_Query Data In Cookie
- How to add custom checkout field in user details mail template
- How to set up and use a custom upload directory for post type ‘product’
- Add specific phrase after every product title including the discounted price? [closed]
- Display Sale Price Before Regular Price (WooCommerce)
- How keep woocommerce users separeted in multisite install and keep admins on network
- Setting WooCommerce currency programmatically
- Exclude specific product tags from related products in WooCommerce 3+ [closed]
- WooCommerce Orders pagination
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- How to create a container in php then customise it in CSS
- Show button in header when product custom field is not empty
- WordPress 6.1.1 UTF8 Slug Limit Increase
- How call WordPress shortcode inside function file
- Woocommerce Convert existing order to the cart
- strict custom php script on specific product category [closed]
- How to change shipping method title based on cart amount?
- How to add SKU and remove product title from WooCommerce url?
- Product Search in search.php
- using custom pages for myaccount in woocommerce
- PHP Add products to cart with WooCommerce Addons