Developer guide
Open the carts from your own buttons, react to cart updates, override templates and filter what's shown. Every example is checked against the code.
Architecture
- Namespaces:
Siteryn\SiterynMiniCartSideCart(Free) andSiteryn\SiterynMiniCartSideCartPro(Pro). - Boot: Free runs on
plugins_loadedand firessiteryn_mcsc_loaded; Pro boots on that hook and firessiteryn_mcsc_pro_loaded. - Pro extends Free only through Free's filters, its own settings option and a replacement
cart-body.phpwhile licensed. Its only write to Free's option is a one-time copy of styling values set in older Pro versions (flagsiteryn_mcsc_pro_free_settings_migrated). - No REST routes, custom tables, post meta or cron. Settings live in
siteryn_mcsc_settings(Pro:siteryn_mcsc_pro_settings).
Opening the carts
Any element can open the Side Cart, no JavaScript needed:
<button type="button" class="my-cart-button" data-siteryn-mcsc-trigger="side-cart" data-siteryn-mcsc-panel-id="siteryn-mcsc-side-cart" aria-controls="siteryn-mcsc-side-cart" aria-haspopup="dialog" aria-expanded="false"> View cart </button>
Or from JavaScript, once the page has loaded (the script is deferred):
document.addEventListener( 'DOMContentLoaded', function () {
document.querySelector( '.my-link' ).addEventListener( 'click', function ( e ) {
e.preventDefault();
if ( window.siterynMcsc ) {
window.siterynMcsc.openSideCart(); // or .openMiniCart()
}
} );
} );
window.siterynMcsc | Does |
|---|---|
openSideCart() | Opens #siteryn-mcsc-side-cart. |
openMiniCart() | Opens the header Mini Cart (Header Cart → Mini Cart), else the first Mini Cart on the page. |
openPanelById( id ) · closePanelById( id ) | Panel ids: siteryn-mcsc-side-cart, siteryn-mcsc-mini-cart-header, siteryn-mcsc-mini-cart-1, -2… |
getCartCount() · getCartSubtotalHtml() | Current values (null until the first update). |
Only one cart is open at a time. In Free, the side cart can be opened after every add to cart with an event:
document.addEventListener( 'siteryn_mcsc_added_to_cart', function () {
window.siterynMcsc && window.siterynMcsc.openSideCart();
} );
JavaScript events
Event (on document) | detail · when |
|---|---|
siteryn_mcsc_added_to_cart | { fragments }. After an add to cart (product form, shop buttons, WooCommerce blocks). |
siteryn_mcsc_item_removed | { panel }. After a remove, or quantity set to 0. |
siteryn_mcsc_fragments_applied | { fragments }. Every time the plugin updates the cart markup. |
siteryn_mcsc_header_cart_icon_rebuilt | The header icon was rebuilt. |
document.addEventListener( 'siteryn_mcsc_fragments_applied', function ( e ) {
var count = window.siterynMcsc.getCartCount();
// e.detail.fragments: selector => HTML
} );
Script configuration
window.siterynMcscConfig, filterable with siteryn_mcsc_script_config:
| Key | Value |
|---|---|
ajaxUrl · nonce | admin-ajax address (with the page's language) and the siteryn_mcsc_cart nonce |
addToCartUrl · redirectToCart | WooCommerce's wc-ajax=add_to_cart endpoint; true when "Redirect to the cart page" is on (no interception) |
minQuantity | Lowest stepper value: 0 (0 removes), or 1 when Lowering Quantity Below 1 is Stops at 1 |
miniCart | { openTrigger, hoverDelay, closeDelay }: Open Type and the Mini Cart's Hover Open Delay / Hover Close Delay in ms (300 / 150 by default) |
headerCart | { active, action, triggerMode, hoverOpenDelay, hoverCloseDelay, selector, showCount, showSubtotal, panelId, … } |
i18n | addedToCart, removedItem, updatedCart, genericError |
How the cart refreshes
The plugin adds its markup to WooCommerce's cart fragments, so it updates wherever WooCommerce updates the cart:
| Fragment selector | Content |
|---|---|
.siteryn-mcsc-count | Count badges |
.siteryn-mcsc-body--mini_cart · .siteryn-mcsc-body--side_cart | Cart bodies |
.siteryn-mcsc-header-subtotal | Header subtotal |
.siteryn-mcsc-title__count | "N items" line |
Add a form attribute data-siteryn-mcsc-skip to stop the plugin intercepting a product form's add to cart. Your own header elements can use WooCommerce's fragments filter:
add_filter( 'woocommerce_add_to_cart_fragments', function ( $fragments ) {
$fragments['.my-header-total'] = '<span class="my-header-total">' . wp_kses_post( WC()->cart->get_cart_subtotal() ) . '</span>';
return $fragments;
} );
PHP examples
add_filter( 'siteryn_mcsc_show_side_cart_trigger', function ( $show ) {
return is_page( 'contact' ) ? false : $show; // the drawer and custom triggers still work
} );
add_filter( 'siteryn_mcsc_render_side_cart', function ( $render ) {
return is_page_template( 'landing.php' ) ? false : $render;
} );
// Same for siteryn_mcsc_render_mini_cart. Return $render unchanged otherwise,
// so Pro's display rules still run.
add_action( 'siteryn_mcsc_cart_item_after_price', function ( $item, $context ) {
$product = wc_get_product( $item['product_id'] );
if ( $product && $product->is_on_backorder( $item['quantity'] ) ) {
echo '<p class="my-mcsc-backorder">' . esc_html__( 'Ships in 2–3 weeks', 'my-theme' ) . '</p>';
}
}, 10, 2 ); // $context: 'mini_cart' or 'side_cart'
add_filter( 'siteryn_mcsc_cart_item_visible', function ( $visible, $cart_item, $key ) {
return empty( $cart_item['my_free_gift'] ) ? $visible : false; // still counted in the badge
}, 10, 3 );
Variation details (size, color…) are switched off for both carts with Show Variation Details on the Appearance tab.
add_filter( 'option_siteryn_mcsc_settings', function ( $settings ) {
if ( ! is_admin() && is_array( $settings ) ) {
$settings['header_cart_enabled'] = true;
$settings['header_cart_selector'] = '.site-header .my-cart-link';
}
return $settings;
} );
add_filter( 'siteryn_mcsc_cart_icons', function ( $icons ) {
$icons['my_bag'] = '<svg viewBox="0 0 24 24" width="22" height="22" fill="currentColor" aria-hidden="true"><path d="M6 7h12l-1 13H7z"/></svg>';
return $icons;
} );
// "my_bag" now appears as "My Bag" in the Mini Cart's Cart Icon and the
// Floating Cart's Icon pickers; choose it there and save.
Register the icon early (for example on plugins_loaded or siteryn_mcsc_loaded), and use only the SVG tags and attributes allowed by siteryn_mcsc_cart_icons_kses_allowed.
Templates
Copy a template from wp-content/plugins/siteryn-mini-cart-side-cart/templates/ to your-theme/siteryn-mini-cart-side-cart/. Each receives one $args array.
| Template | Renders |
|---|---|
mini-cart.php | Mini Cart trigger and dropdown |
side-cart.php | Side Cart overlay and drawer |
side-cart-trigger.php | Floating button |
cart-body.php | Items, subtotal, buttons and empty state (both carts) |
cart-item.php | One item ($args['item'], $args['context']) |
count-badge.php | The count badge |
notifications.php | The notification region |
All are @version 1.0.0; an admin notice lists theme copies that become outdated. Keep the markup contract:
- Panels:
id,data-siteryn-mcsc-panel,hidden,aria-hidden; close buttonsdata-siteryn-mcsc-close; triggersdata-siteryn-mcsc-trigger+data-siteryn-mcsc-panel-id. - Body root:
siteryn-mcsc-body siteryn-mcsc-body--{mini_cart|side_cart}+data-siteryn-mcsc-body. - Items:
li.siteryn-mcsc-item[data-siteryn-mcsc-cart-item-key]; quantity[data-siteryn-mcsc-qty-decrease],[data-siteryn-mcsc-qty-increase],[data-siteryn-mcsc-qty-input]; remove[data-siteryn-mcsc-remove-item]. - Count:
.siteryn-mcsc-count[data-siteryn-mcsc-count]. Keepdo_action( 'siteryn_mcsc_cart_item_after_price', $item, $context )incart-item.php. - An element inside a panel that handles Esc itself can carry
data-siteryn-mcsc-handles-escape, so the panel doesn't close.
cart-body.php, so a theme copy is ignored. To force yours:
add_filter( 'siteryn_mcsc_locate_template', function ( $path, $name ) {
$theme = locate_template( 'siteryn-mini-cart-side-cart/' . $name );
return ( 'cart-body.php' === $name && $theme ) ? $theme : $path;
}, 20, 2 );
AJAX endpoints
| Action (admin-ajax) | Params · nonce |
|---|---|
siteryn_mcsc_update_quantity | cart_item_key, quantity (0 removes) · siteryn_mcsc_cart |
siteryn_mcsc_remove_item | cart_item_key · siteryn_mcsc_cart |
siteryn_mcsc_get_cart_state | Read-only, no nonce |
siteryn_mcsc_pro_apply_coupon · _remove_coupon Pro | coupon_code · siteryn_mcsc_cart |
Free's actions return { fragments, count, cart_url, checkout_url, nonce }; after a successful quantity change or removal the script switches to the returned fresh nonce; Pro's coupon actions return { fragments, applied_coupons } (or an error message), and answer 403 while the license is inactive or the coupon field is off. The nonce is in window.siterynMcscConfig.nonce (Pro also exposes window.siterynMcscProConfig).
wp-config constants
SCRIPT_DEBUG: serves unminified CSS.SITERYN_FEEDBACK_ENDPOINT: deactivation survey address.SITERYN_MCSC_PRO_LICENSE_API_BASE·SITERYN_MCSC_PRO_LICENSE_PRODUCT_IDPro: license server for staging tests.
See the Hooks reference for every action and filter.