We found this method from Jackson who is an experienced WordPress specialist. He talks about adding a simple code to redirect customers from add to cart directly to checkout in WooCommerce.
Jackson’s Code
// Redirect to checkout after add to cart
add_filter('woocommerce_add_to_cart_redirect', 'custom_redirect_to_checkout');
function custom_redirect_to_checkout($url) {
return wc_get_checkout_url();
}
Note: To try, you can add this via Code Snippet (a safe approach).
Is this a good way to get more sales?
If you’re lucky enough to meet a rushed customer who really needs the product, then maybe you’ll get a sale. However, this approach has several significant drawbacks:
- If store owners encourage customers to do checkout right away, they will not make extra purchases – Customers lose the opportunity to browse and add more items to their cart, reducing your average order value.
- It can cause frustration like you force customers to buy – Pushing people directly to checkout feels aggressive and pressuring, which can turn customers away from completing their purchase.
- You don’t allow customers to do shopping which is no good at all – Shopping is often a browsing experience where people want to compare products, read reviews, and make thoughtful decisions before committing to buy.
- His code works but in some cases like some themes use AJAX for add-to-cart buttons. This redirect might not work with all AJAX implementations. If you don’t have technical knowledge, you will be confused.
What WooCommerce Owners Should Do
Respect the customer buying journey. They need to see your store, your products, everything. If they make a purchase which means they really like you and they will come back.
If you find this method interesting, you can try with:
For specific products:
php// Only for specific products
add_filter('woocommerce_add_to_cart_redirect', function($url) {
$product_ids = [123, 456]; // Specific product IDs
$added_product_id = absint($_REQUEST['add-to-cart'] ?? 0);
if (in_array($added_product_id, $product_ids)) {
return wc_get_checkout_url();
}
return $url;
});
Using product meta
php// Redirect based on product meta field
add_filter('woocommerce_add_to_cart_redirect', function($url) {
$added_product_id = absint($_REQUEST['add-to-cart'] ?? 0);
if (get_post_meta($added_product_id, '_direct_checkout', true) === 'yes') {
return wc_get_checkout_url();
}
return $url;
});
But anyways, test for a few days, then make your decision. Advice sometimes can be variant depending on how everything will result.