Using Swift
This walkthrough takes a fresh install to a working Buy Now flow, then covers the shortcode, theming and the developer hooks.
1. Enable and label the button
Section titled “1. Enable and label the button”Open WooCommerce > Buy Now Button, keep Enable Buy Now on, and set the Button label. Left empty, the button reads Buy now in the site language. The live preview updates as you type.
2. Choose placement and redirect
Section titled “2. Choose placement and redirect”Pick where the button appears, single product, shop loops, or both, and on the product page decide whether it sits before or after add-to-cart. Set Redirect to to Checkout (skip the cart), the default and the usual setup. The other choices are Cart and Custom page on this site; a custom address must be on your own site, anything else (or an empty field) sends the shopper to the checkout.
3. Decide on cart clearing and quantity
Section titled “3. Decide on cart clearing and quantity”- Leave Empty the cart first on so Buy Now means “buy only this product now”; turn it off to keep whatever is already in the cart.
- Leave Respect quantity on if a shopper who sets quantity 3 should buy three units. Off, Buy Now buys exactly one. This applies to single, simple products only. It is on for new installs; sites upgraded from before 1.1.0 that never saved this setting keep it off until you switch it on.
4. Confirm on the storefront
Section titled “4. Confirm on the storefront”Open a simple, in-stock product. The Buy Now button appears beside add-to-cart. On the product page the button is a second submit button inside WooCommerce’s own add-to-cart form (formmethod="post"), so the quantity box goes with it. In the shop loop and in the shortcode it is a small GET form that sends the product id and a nonce to the product permalink. Either way Swift adds the product and redirects to your chosen target. Out-of-stock, non-purchasable and variable products show no button.
Placing the button with the shortcode
Section titled “Placing the button with the shortcode”When you want Buy Now somewhere the automatic placements do not reach, a landing page, a block, a custom layout, use the shortcode:
[swift_buy_now][swift_buy_now id="123"]| Attribute | Default | Meaning |
|---|---|---|
id |
0 |
Product ID. 0 or no attribute uses the current post, for example inside a product template. |
That is the only attribute. The shortcode renders nothing when Buy Now is disabled, when the product is missing, out of stock or not purchasable, and for variable products. Its button uses the same template and data as the hooked button. The button stylesheet is enqueued when the shortcode renders, so plain pages without a button load nothing.
What happens on click
Section titled “What happens on click”Swift intercepts the request on template_redirect (priority 5) when the swift_buy_now key is present, then:
- Verifies the nonce (action
swift_buy_now). An expired nonce, for example from a cached page, shows the notice “This page had been open too long, so Buy now did not go through. Please try again.” and the reloaded page carries a fresh one. - Re-checks that the product exists, is purchasable, in stock and not variable.
- Reads the quantity from the form only when Respect quantity is on; otherwise it uses 1.
- Empties the cart when Empty the cart first is on, then adds the product.
- If the add fails (stock or validation), restores the previous cart contents and applied coupons and shows the notice “Sorry, this product could not be added to your cart.”, so the shopper loses nothing.
- Resolves the redirect URL from Redirect to, passes it through the filter below, and redirects with
wp_safe_redirect().
There is no filter for cart clearing; it is the Empty the cart first setting (clear_cart, default on).
Common scenarios
Section titled “Common scenarios”- Single-product landing page. Redirect to checkout, leave empty-cart on, and drop
[swift_buy_now id="123"]under your sales copy, one click goes straight to pay. - Express shortcut beside add-to-cart. Keep add-to-cart primary, place Buy Now after it, and turn empty-cart off so shoppers can still build a multi-item cart the normal way.
- Catalogue quick buy. Enable the loop placement so high-intent shoppers can buy a simple product straight from the shop grid. Product grids built from blocks get the button after each Add to cart block too.
Theming the button with CSS
Section titled “Theming the button with CSS”The storefront button reads six custom properties set on the .swift-buy-now wrapper. Override them from your theme stylesheet:
| Property | Default | Controls |
|---|---|---|
--swift-accent-color |
#5b3df5 |
Fill and border of the solid and outline styles, press effect |
--swift-accent-contrast-color |
#fff |
Text on the solid style |
--swift-button-radius |
6px |
Corner radius |
--swift-button-gap |
0.5em |
Space between Buy Now and add-to-cart |
--swift-button-transition |
150ms cubic-bezier(0.2, 0.8, 0.2, 1) |
Hover and press timing |
--swift-button-thrust |
3px |
How far the label moves forward on press |
.swift-buy-now { --swift-accent-color: #0a7c3f; --swift-accent-contrast-color: #fff; --swift-button-radius: 4px; --swift-button-gap: 0.75em;}Set them on .swift-buy-now, not on the button: the wrapper resolves them. An Accent colour saved in the settings is printed as --swift-accent on the same wrapper and wins over --swift-accent-color from the theme. The Theme default style inherits your theme’s own .button and ignores the accent. Dark-scheme colours, focus-visible rings and a prefers-reduced-motion guard are built in. There is no theme template-override path; the button markup lives in the plugin.
Changing the redirect (developers)
Section titled “Changing the redirect (developers)”Before redirecting, Swift passes the target URL through a filter:
apply_filters( 'wppoland_direct_checkout_redirect_url', string $url, WC_Product $product, string $request_key );| Argument | Value |
|---|---|
$url |
The URL from Redirect to: checkout, cart or your same-site custom page |
$product |
The product just added |
$request_key |
swift_buy_now for the free button |
add_filter( 'wppoland_direct_checkout_redirect_url', function ( string $url, WC_Product $product, string $request_key ): string { // Route one product to a custom one-page checkout. if ( 'swift_buy_now' === $request_key && $product->get_id() === 123 ) { return home_url( '/express/' ); }
return $url;}, 10, 3 );The filtered URL still goes through wp_validate_redirect() with the checkout as fallback, so an address on another domain lands on the checkout unless that host is allowed through allowed_redirect_hosts. Swift Pro hooks the same filter for its per-product redirect rule and fires it from its own variable-product handler with the key swift_pro_buy_now; check $request_key if your code should touch only one of them.
Other hooks
Section titled “Other hooks”| Hook | Type | Arguments | When |
|---|---|---|---|
swift/booted |
action | Swift\Plugin $plugin |
After Swift has registered all its hooks; add-on code can start here |
swift/show_pro_cta |
filter | bool $show (default true) |
Return false to hide the Swift Pro promotion in wp-admin |
swift/pro_url |
filter | string $url |
Change the link used by that promotion |
Performance and accessibility notes
Section titled “Performance and accessibility notes”The button is server-rendered in PHP and sits in the normal flow, so it adds no layout shift. On the storefront Swift loads one small stylesheet and no JavaScript: on shop, cart and checkout pages when the feature is enabled, and elsewhere only where a button actually rendered. The on-page quantity needs no script, because the product-page button submits the cart form it sits in. The admin help affordances are keyboard-operable ? buttons tied to their tooltips via aria-describedby.
Buy Now in Cartdock and Peek
Section titled “Buy Now in Cartdock and Peek”- Cartdock sticky bar. With Cartdock’s Swift checkbox on, simple products show the Buy Now button in the sticky bar next to Add to cart.
- Peek quick view. When a product opens in Peek’s quick view, Buy Now goes straight to checkout, as on the product page, and Add to cart still adds through the quick view without leaving the shop page. This needs Peek 1.1.4 or later: older Peek versions sent Buy Now through the quick view’s own add to cart.