Shopify店铺技术问询:跳过购物车直结账及添加集合页Buy now按钮
1. How to Skip the Cart and Go Straight to Checkout in Shopify
Got it, here are a few proven ways to cut out the cart page entirely, depending on your needs:
Option 1: Use Shopify's Built-In Direct Checkout
This is the easiest route if you just want a "Buy Now" button on product pages that skips the cart:
- Head to your Shopify admin → Settings → Checkout
- Scroll down to the Shopping cart section
- Flip the toggle for "Allow customers to check out directly from the product page"—this adds a "Buy now" button next to your regular "Add to cart" button, which takes users straight to checkout.
Option 2: Auto-Redirect from Cart to Checkout
If you want anyone who accidentally lands on the cart page to be sent straight to checkout, edit your theme's cart template:
- Go to Online Store → Themes → Actions → Edit code
- Find
cart.liquid(orcart-template.liquid—the exact name depends on your theme) - Drop this script at the bottom of the file:
window.location.href = '/checkout';
Save your changes, and now the cart page will immediately redirect to checkout.
Option 3: Modify Add-to-Cart Buttons to Point Directly to Checkout
For full control, change the form action on your add-to-cart buttons to go straight to checkout instead of the cart:
- In your product template (like
product.liquidorproduct-form.liquid), locate the<form>tag that handles adding items to cart - Swap the
action="/cart/add"attribute withaction="/checkout" - Make sure the form still includes all required fields:
id(for the product variant) andquantity
Adding a "Buy Now" button to your collection grid is straightforward with a bit of theme code tweaking. Here's how:
- Access your theme code: Shopify admin → Online Store → Themes → Actions → Edit code
- Find the collection product snippet: Look for files like
product-grid-item.liquid,card-product.liquid, orcollection.liquid—this is the file that renders each individual product in your collection grid. - Add the button code:
- Locate the existing "Add to cart" button block in that snippet
- Paste this code right next to it (adjust the CSS classes to match your theme's styling):
<form action="/cart/add" method="post" class="buy-now-form"> <input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}"> <input type="hidden" name="quantity" value="1"> <button type="submit" class="button buy-now-button">Buy Now</button> </form>- If you want this button to skip the cart and go straight to checkout (matching your first request), change
action="/cart/add"toaction="/checkout"
- Style the button: Add some CSS to make it fit your theme. Pop this into your theme's
base.cssortheme.cssfile:.buy-now-button { background: #0070f3; color: white; border: none; padding: 8px 12px; margin-left: 6px; border-radius: 4px; cursor: pointer; } .buy-now-button:hover { background: #005bb5; } - Test thoroughly: Save your changes, then visit a collection page. Click the new "Buy Now" button—should add the product to your cart (or take you to checkout if you adjusted the action).
Quick Notes:
- If your collection has products with variants (sizes, colors, etc.), this code will use the first available variant. To handle variant selection directly in the collection grid, you'd need to add a variant picker, which is a bit more involved.
- Always duplicate your theme before making code changes—this way you can revert if something goes wrong.
内容的提问来源于stack exchange,提问作者user49799
相关产品推荐
相关产品推荐

