Skip Checkout for Free Products in WooCommerce
If you’re running an online store with WooCommerce and you offer free products, you may want to streamline the process for customers by skipping the checkout page. This can improve the user experience and reduce friction for free product purchases. In this post, we’ll explore two methods for skipping the checkout process when customers add free products to their cart.
For those who prefer a quick, easy solution without any coding, using a plugin is the most efficient way to skip the checkout process for free products in WooCommerce. There are a few plugins that allow you to bypass the checkout page for orders that contain only free items:
The WooCommerce Direct Checkout plugin streamlines the checkout process by skipping the cart page and redirecting users directly to the checkout page. However, if their cart contains only free products, you can configure it to redirect users to a custom page (such as a thank you page).
You can download and install the plugin from the WordPress repository, then configure it from the WooCommerce settings to automatically redirect customers when their cart total is zero.
Another great plugin is the WooCommerce Checkout Manager, which lets you customize the checkout process extensively. You can use this plugin to create rules for free products, such as skipping the checkout page entirely or displaying a special message to customers when they’re purchasing free items.
Both of these plugins offer flexible solutions and can be customized based on your store’s needs.
For those who prefer a more hands-on approach, you can skip the checkout for free products by adding custom code to your theme’s functions.php
file. Here’s a simple PHP snippet that checks if the cart’s total is zero (i.e., the cart contains only free products) and redirects users to a custom page instead of the checkout page.
// Skip checkout for free products and automatically complete the order
add_action('template_redirect', 'skip_checkout_for_free_products');
function skip_checkout_for_free_products() {
// Only proceed if we're on the cart or checkout page
if ((is_cart() || is_checkout()) && !is_order_received_page()) {
$cart_total = WC()->cart->get_total('edit');
// Check if the cart contains only free products (total is 0)
if ($cart_total == 0) {
// Create an order with free products
$order = wc_create_order();
// Add the products in the cart to the order
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$order->add_product($cart_item['data'], $cart_item['quantity']);
}
// Calculate the order totals
$order->calculate_totals();
// Mark the order as completed
$order->set_status('completed');
$order->save();
// Empty the cart
WC()->cart->empty_cart();
// Redirect to the order received page (thank you page)
wp_redirect($order->get_checkout_order_received_url());
exit;
}
}
}
// Automatically mark orders containing only free products as "completed"
add_action('woocommerce_checkout_order_processed', 'auto_complete_order_for_free_products', 10, 1);
function auto_complete_order_for_free_products($order_id) {
// Get the order object
$order = wc_get_order($order_id);
// Flag to check if all items are free
$free_products = true;
// Loop through each item in the order
foreach ($order->get_items() as $item) {
if ($item->get_total() > 0) {
// If an item has a price greater than 0, it's not free
$free_products = false;
break;
}
}
// If all products are free, mark the order as completed
if ($free_products) {
$order->update_status('completed');
}
}
By skipping the checkout process for free products, you can provide a smoother experience for customers. It also reduces the time spent on checkout forms and ensures that customers don’t accidentally abandon free orders due to complex checkout processes.
Some use cases for skipping checkout include:
If you want to skip the checkout process for free products in WooCommerce, you can either use a plugin like WooCommerce Direct Checkout or WooCommerce Checkout Manager for a simple solution or add custom code to your theme for more control.
Each method has its benefits, so choose the one that best fits your store’s needs. Either way, streamlining the process for free product purchases can enhance your customers’ experience and boost conversions.