assets | ||
buy-now-button.php | ||
README.md |
Buy Now Button for WooCommerce
A lightweight WooCommerce plugin that adds a Buy Now button to product pages and shop archives.
It lets customers add products instantly and go straight to Checkout, streamlining the flow and reducing cart abandonment.
Table of Contents
- ✨ Features
- ✅ Requirements
- 📥 Installation
- ⚙️ Configuration
- 🔧 Usage
- 🛠️ Development Notes
- 🧩 Troubleshooting
- 🗒️ Changelog
- 📄 License
- 👨💻 Author
✨ Features
- Buy Now button on:
- Single product pages (below Add to Cart; supports simple & variable products).
- Shop/archive pages (for simple products).
- Direct-to-checkout after add-to-cart via AJAX, with a non-JS fallback.
- Customization UI in WP Admin → WooCommerce → Buy Now Button:
- Button Text (e.g., “Buy Now”, “Quick Checkout”, etc.)
- Text Align: Left / Center / Right (default: Center)
- Colors: Normal / Hover / Active (hex input + color picker)
- Border Radius (px)
- Animation: None, Pulse, Bounce, Wiggle, Shake, Glow, Ripple
- Animation Trigger: Hover or Always (Normal)
- Works nicely with caching/CDN and heavy themes (injects dynamic CSS with
!important
). - Clean, lightweight, and developer-friendly.
✅ Requirements
- WordPress
- WooCommerce
📥 Installation
Option A — Upload Folder
- Download or clone this repository.
- Upload the plugin folder to
wp-content/plugins/
. - Activate it from WordPress → Plugins.
Option B — Upload ZIP
- Zip the plugin folder.
- Go to Plugins → Add New → Upload Plugin and upload the ZIP.
- Activate.
⚙️ Configuration
Open WooCommerce → Buy Now Button and configure:
- Button Text
- Button Text Align — Left / Center / Right (default: Center)
- Colors — set hex (or use the color picker) for:
- Normal
- Hover
- Active
- Border Radius — in pixels
- Animation — None, Pulse, Bounce, Wiggle, Shake, Glow, Ripple
- Animation Trigger — Apply on Hover or Always (Normal)
After saving, purge your cache if you use a caching plugin or CDN.
🔧 Usage
- Single product pages: A Buy Now button appears under Add to Cart.
For variable products, the chosen attributes & variation are respected. - Shop/archive pages: A Buy Now button appears for simple products.
- Behavior: Clicking Buy Now adds the item to cart (AJAX) and immediately redirects to Checkout.
With JavaScript disabled, a fallback route handles add-to-cart and redirects to Checkout.
🛠️ Development Notes
-
The plugin keeps existing cart items by default. If you’d rather replace the cart contents on Buy Now, in
buy-now-button.php
(AJAX handler) uncomment:// WC()->cart->empty_cart();
-
Buttons include animation classes (e.g., bn-anim-pulse). When Animation Trigger is set to Always, the class bn-anim-normal is also appended. Dynamic CSS is injected at runtime using wp_add_inline_style and marked with !important to defeat overly aggressive theme rules.
🧩 Troubleshooting
Settings don’t apply (colors/radius/text/align)
- Purge any page/cache plugin and your CDN; hard-refresh the page (Ctrl/Cmd + Shift + R).
- Ensure the plugin is active and you saved changes.
- Inspect the page
<head>
for inline styles injected for handleabb-bn-css
. If missing, verify theme doesn’t deregister styles.
Clicking Buy Now doesn’t redirect to Checkout
- Make sure WooCommerce is active.
- Check browser console (F12 → Console) for JS errors.
- Security plugins or firewalls sometimes block
admin-ajax.php
. Whitelist it and ensure it’s not cached. - If you see
403
or nonce errors, log out/in or clear server-side caches that might cache logged-in pages.
Variable product won’t add
- Ensure a valid variation is selected (dropdowns/attributes) before clicking Buy Now.
Button not visible
- On archives, the button shows for simple products only (by design).
If your theme overrides Woo hooks/templates, confirm it still calls:woocommerce_after_add_to_cart_button
(single)woocommerce_after_shop_loop_item
(archive)
Conflicts with other Buy Now/checkout plugins
- Disable other similar plugins to avoid duplicate handlers, CSS, or AJAX actions.
Replace (not append) cart contents on Buy Now
- In
buy-now-button.php
, inside the AJAX handler, uncomment:// WC()->cart->empty_cart();
🗒️ Changelog
1.4.0
- Added Button Text Align (Left / Center / Right). Default: Center.
1.3.0
- Added Button Text customization.
- Added Animation Trigger (Hover / Always).
- Added Hex color inputs with WordPress Color Picker.
1.2.0
- Switched to AJAX add-to-cart + redirect (with non-JS fallback).
- Improved reliability with caching/CDN and heavy themes.
1.1.0
- Initial customization options (colors, animation, radius) + settings UI.
📄 License
MIT — use, modify, and distribute freely.
👨💻 Author
absoftlab
Website: https://absoftlab.com