WooCommerce Cart Link Admin Bar
Adds a cart link to the WordPress admin bar for easy access to the WooCommerce cart.
by Brian Coords · github.com/bacoords/woo-cart-link-admin-bar · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/bacoords/woo-cart-link-admin-bar/archive/refs/heads/main.zipReadme
WooCommerce Cart Link Admin Bar
A WordPress plugin that adds a convenient cart link to the WordPress admin bar, allowing users to quickly copy a checkout link with their current cart contents.
Description
The WooCommerce Cart Link Admin Bar plugin enhances the WordPress admin bar by adding a "Copy Checkout Link" button that appears when users are on the cart page. This button fetches the current cart contents using the WooCommerce Store API and generates a checkout link that includes all products and applied coupons, which can then be copied to the clipboard with a single click.
Features
- Admin Bar Integration: Adds a cart link button to the WordPress admin bar
- Smart Cart Detection: Only shows the button when users are on the cart page
- WooCommerce Store API Integration: Uses the modern WooCommerce Store API to fetch cart data
- Automatic Link Generation: Generates checkout links with product IDs, quantities, and coupon codes
- Clipboard Integration: Copies the generated checkout link to the clipboard automatically
- Visual Feedback: Provides visual confirmation when the link is copied
- Fallback Support: Includes fallback clipboard functionality for older browsers
- Clean UI: Uses WordPress dashicons for consistent styling
Requirements
- WordPress 5.0 or higher
- WooCommerce plugin 10.0.0 or higher (active)
- PHP 7.4 or higher
- Modern web browser with clipboard API support (fallback available for older browsers)
Installation
Method 1: Manual Installation
- Download the plugin files
- Upload the
woo-cart-link-admin-barfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Navigate to your cart page to see the new admin bar button
Method 2: Git Clone
cd wp-content/plugins/
git clone https://github.com/your-username/woo-cart-link-admin-bar.git
Then activate the plugin through the WordPress admin panel.
Usage
- Navigate to Cart Page: Go to your WooCommerce cart page (
/cart/) - Locate Admin Bar Button: Look for the "Copy Checkout Link" button in the WordPress admin bar
- Click to Copy: Click the button to automatically copy the checkout link to your clipboard
- Share the Link: Paste the copied link anywhere to share your cart contents
How It Works
The plugin works by:
- Detecting Cart Page: Only shows the button when users are on the cart page
- Fetching Cart Data: Uses the WooCommerce Store API to get current cart contents
- Generating Checkout Link: Creates a URL with product IDs, quantities, and coupon codes
- Copying to Clipboard: Automatically copies the generated link to the clipboard
- Providing Feedback: Shows visual confirmation that the link was copied
Generated Link Format
The plugin generates checkout links in the following format:
https://yoursite.com/checkout-link/?products=123:2,456:1&coupon=SAVE10
Where:
productsparameter containsproduct_id:quantitypairscouponparameter contains applied coupon codes (if any)
Configuration
The plugin requires no configuration and works out of the box. However, you may need to ensure:
- WooCommerce is Active: The plugin requires WooCommerce to be installed and activated
- Admin Bar is Visible: The admin bar must be visible for the button to appear
- Cart Page Exists: Your site must have a cart page at
/cart/
Browser Compatibility
- Modern Browsers: Full clipboard API support with automatic copying
- Older Browsers: Fallback clipboard functionality using
document.execCommand() - Mobile Browsers: Limited clipboard support, may require manual copying
Development
File Structure
woo-cart-link-admin-bar/
├── woo-cart-link-admin-bar.php # Main plugin file
├── woo-cart-link-admin-bar.js # JavaScript functionality
└── README.md # This file
Key Functions
wclab_init(): Plugin initializationwclab_add_cart_link_to_admin_bar(): Adds the admin bar buttonwclab_enqueue_scripts_if_checkout(): Enqueues JavaScript on cart pagefetchCart(): Fetches cart data from WooCommerce Store APIgenerateCheckoutLink(): Generates checkout link from cart datahandleCartLinkClick(): Handles button click events
Hooks and Filters
The plugin uses the following WordPress hooks:
plugins_loaded: Plugin initializationadmin_bar_menu: Admin bar menu integrationwp_enqueue_scripts: Script enqueuing
Troubleshooting
Common Issues
-
Button Not Appearing
- Ensure you're on the cart page (
/cart/) - Check that the admin bar is visible
- Verify WooCommerce is active
- Ensure you're on the cart page (
-
Link Not Copying
- Check browser console for JavaScript errors
- Ensure your browser supports the clipboard API
- Try refreshing the page
-
Cart Data Not Loading
- Verify WooCommerce Store API is accessible
- Check for any JavaScript errors in the browser console
- Ensure the cart page is properly configured
Debug Mode
Enable WordPress debug mode to see detailed error messages:
// Add to wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Changelog
Version 1.0.0
- Initial release
- Admin bar integration
- WooCommerce Store API integration
- Clipboard functionality
- Visual feedback system
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
This plugin is licensed under the GPL v2 or later.
Support
For support, feature requests, or bug reports, please:
- Check the troubleshooting section above
- Search existing issues on GitHub
- Create a new issue with detailed information
Credits
- Author: Brian Coords
- License: GPL v2 or later
- Requires: WordPress 5.0+, WooCommerce 10.0.0+, PHP 7.4+
Note: This plugin is designed to work with WooCommerce and requires the WooCommerce plugin to be installed and activated on your WordPress site.