WP Manifestindependent plugin directory
manifest / ecommerce / woo-cart-link-admin-bar

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

2stars
0forks

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.zip

Readme

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

  1. Download the plugin files
  2. Upload the woo-cart-link-admin-bar folder to the /wp-content/plugins/ directory
  3. Activate the plugin through the 'Plugins' menu in WordPress
  4. 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

  1. Navigate to Cart Page: Go to your WooCommerce cart page (/cart/)
  2. Locate Admin Bar Button: Look for the "Copy Checkout Link" button in the WordPress admin bar
  3. Click to Copy: Click the button to automatically copy the checkout link to your clipboard
  4. Share the Link: Paste the copied link anywhere to share your cart contents

How It Works

The plugin works by:

  1. Detecting Cart Page: Only shows the button when users are on the cart page
  2. Fetching Cart Data: Uses the WooCommerce Store API to get current cart contents
  3. Generating Checkout Link: Creates a URL with product IDs, quantities, and coupon codes
  4. Copying to Clipboard: Automatically copies the generated link to the clipboard
  5. 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:

  • products parameter contains product_id:quantity pairs
  • coupon parameter contains applied coupon codes (if any)

Configuration

The plugin requires no configuration and works out of the box. However, you may need to ensure:

  1. WooCommerce is Active: The plugin requires WooCommerce to be installed and activated
  2. Admin Bar is Visible: The admin bar must be visible for the button to appear
  3. 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 initialization
  • wclab_add_cart_link_to_admin_bar(): Adds the admin bar button
  • wclab_enqueue_scripts_if_checkout(): Enqueues JavaScript on cart page
  • fetchCart(): Fetches cart data from WooCommerce Store API
  • generateCheckoutLink(): Generates checkout link from cart data
  • handleCartLinkClick(): Handles button click events

Hooks and Filters

The plugin uses the following WordPress hooks:

  • plugins_loaded: Plugin initialization
  • admin_bar_menu: Admin bar menu integration
  • wp_enqueue_scripts: Script enqueuing

Troubleshooting

Common Issues

  1. Button Not Appearing

    • Ensure you're on the cart page (/cart/)
    • Check that the admin bar is visible
    • Verify WooCommerce is active
  2. Link Not Copying

    • Check browser console for JavaScript errors
    • Ensure your browser supports the clipboard API
    • Try refreshing the page
  3. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This plugin is licensed under the GPL v2 or later.

Support

For support, feature requests, or bug reports, please:

  1. Check the troubleshooting section above
  2. Search existing issues on GitHub
  3. 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.

Read the full README on GitHub →