Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/tajwar-t/wc-cart-popup/archive/refs/heads/main.zipPlugin Name: WooCommerce Cart Popup
Version: 1.0.6
Author: Tajwar
License: GPL-2.0+
Requires: WordPress 5.0+, WooCommerce 3.0+
Tested Up To: WordPress 6.6, WooCommerce 9.0
Description
WooCommerce Cart Popup enhances the shopping experience by displaying a sleek, centered popup when a product is added to the cart via AJAX. The popup provides visual feedback with a loading spinner, product image, success message, and action buttons, ensuring a user-friendly and responsive interface across all devices.
Features
- Centered Popup: Displays a popup centered on the screen using CSS
position: fixed,top: 50%,left: 50%, andtransform: translate(-50%, -50%)for consistent positioning across all screen sizes. - Loading Spinner: Shows a spinning loader during the AJAX request to indicate processing.
- Product Image: Displays the product’s thumbnail (100x100px, rounded corners) after the AJAX request completes successfully.
- Success Message: Shows a customizable success message in the format "1x Product Name added to the cart!" with the quantity and product name in bold.
- Action Buttons: Includes "Continue Shopping" and "View Cart" buttons with uniform styling (uppercase text, 45px height, flex alignment) and hover effects.
- Close Button: A prominent close button (
×) in the top-right corner to dismiss the popup. - Responsive Design: Adapts to all screen sizes with media queries for mobile devices (
<600pxand<400px), adjusting popup width, image size, font sizes, and button layout. - Debugging Support: Includes console logs for troubleshooting (e.g., button clicks, AJAX requests, computed styles for centering).
- Theme Compatibility: Uses high-specificity selectors (
body #wcCartPopup) to minimize conflicts with themes. - Variable Product Support: Handles both simple and variable products, extracting product or variation IDs from buttons or forms.
Installation
-
Download and Upload:
- Download the plugin zip file or clone the repository.
- Upload the
wc-cart-popupfolder towp-content/plugins/via FTP or use the WordPress admin panel to upload the zip file (Plugins > Add New > Upload Plugin).
-
Activate:
- Navigate to
Pluginsin the WordPress admin dashboard. - Activate the WooCommerce Cart Popup plugin.
- Navigate to
-
Verify Dependencies:
- Ensure WooCommerce is installed and active. If not, an admin notice will prompt you to install WooCommerce.
-
Clear Caches:
- Clear any WordPress caching plugins (e.g., WP Super Cache, W3 Total Cache).
- Clear your browser cache to ensure the plugin’s CSS and JavaScript load correctly.
Usage
-
Adding Products:
- On any WooCommerce product page (simple or variable), click the "Add to Cart" button (e.g.,
<button type="submit" name="add-to-cart" value="27" class="single_add_to_cart_button">Add to cart</button>). - The plugin captures clicks on buttons with classes like
.add_to_cart_button,.ajax_add_to_cart,.single_add_to_cart_button, or attributes likename="add-to-cart".
- On any WooCommerce product page (simple or variable), click the "Add to Cart" button (e.g.,
-
Popup Behavior:
- Upon clicking "Add to Cart":
- A centered overlay (
#wcCartOverlay) darkens the background. - The popup (
#wcCartPopup) appears with a loading spinner and close button. - The product image, success heading ("Success!"), success message ("1x Product Name added to the cart!"), and action buttons are hidden during loading.
- After the AJAX request completes successfully, the spinner hides, and the product image, success heading, message, and buttons ("Continue Shopping" and "View Cart") appear.
- A centered overlay (
- If the AJAX request fails, the popup closes, and an alert displays the error (e.g., "Invalid product ID").
- Upon clicking "Add to Cart":
-
Closing the Popup:
- Click the close button (
×) or the "Continue Shopping" button to dismiss the popup. - The "View Cart" button redirects to the WooCommerce cart page.
- Click the close button (
-
Responsive Experience:
- On mobile devices (
<600px), the popup width reduces to 85%, the product image shrinks to 80x80px, and buttons stack vertically. - On very small screens (
<400px), the popup width further reduces to 90% with smaller padding.
- On mobile devices (
Troubleshooting
If the popup doesn’t appear, appears misaligned, or the image/message doesn’t show:
-
Check Console Logs:
- Open Developer Tools (F12 > Console) and click "Add to Cart".
- Look for logs like:
WCCartPopup: Adding product ID 27 to cart with quantity 1WCCartPopup: Computed styles - display: block, position: fixed, top: 50%, left: 50%, transform: matrix(...)WCCartPopup: Product image src https://.../product.jpg
- Check for errors like
WCCartPopup: AJAX error.
-
Verify CSS/JS Loading:
- In Developer Tools (F12 > Network), confirm
wc-cart-popup.cssandwc-cart-popup.jsload (status 200). - Inspect
#wcCartPopupin the Elements tab to ensure it has theshowclass and styles (display: block,top: 50%, etc.).
- In Developer Tools (F12 > Network), confirm
-
Theme Conflicts:
- Test with the Storefront theme to rule out conflicts.
- Ensure
footer.phpincludes<?php wp_footer(); ?>.
-
Debug Log:
Enable debugging in wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
- Check
wp-content/debug.logfor errors likeWCCartPopup.
-
Product Image Issues:
- If the product image doesn’t appear, ensure the product has a featured image in WooCommerce.
- Check the console for
WCCartPopup: Product image src.
-
Variable Products:
- For variable products, ensure the
<form class="cart">includesvariation_idorproduct_idinputs.
- For variable products, ensure the
File Structure
wc-cart-popup/
├── wc-cart-popup.php # Main plugin file (handles HTML, AJAX, and enqueues)
├── js/
│ └── wc-cart-popup.js # JavaScript for AJAX and popup logic
├── css/
│ └── wc-cart-popup.css # Styles for popup, buttons, and responsive design
├── README.md # This file
Support
For issues or feature requests, please contact the author or open an issue on the plugin’s repository (if available). Provide console logs, theme name, and details about the product type (simple or variable) for faster resolution.
License
This plugin is licensed under the GPL-2.0+ License.