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.

FreePro

Architecture

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.siterynMcscDoes
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_rebuiltThe 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:

KeyValue
ajaxUrl · nonceadmin-ajax address (with the page's language) and the siteryn_mcsc_cart nonce
addToCartUrl · redirectToCartWooCommerce's wc-ajax=add_to_cart endpoint; true when "Redirect to the cart page" is on (no interception)
minQuantityLowest 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, … }
i18naddedToCart, 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 selectorContent
.siteryn-mcsc-countCount badges
.siteryn-mcsc-body--mini_cart · .siteryn-mcsc-body--side_cartCart bodies
.siteryn-mcsc-header-subtotalHeader 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.

TemplateRenders
mini-cart.phpMini Cart trigger and dropdown
side-cart.phpSide Cart overlay and drawer
side-cart-trigger.phpFloating button
cart-body.phpItems, subtotal, buttons and empty state (both carts)
cart-item.phpOne item ($args['item'], $args['context'])
count-badge.phpThe count badge
notifications.phpThe notification region

All are @version 1.0.0; an admin notice lists theme copies that become outdated. Keep the markup contract:

While Pro is licensed it uses its own 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_quantitycart_item_key, quantity (0 removes) · siteryn_mcsc_cart
siteryn_mcsc_remove_itemcart_item_key · siteryn_mcsc_cart
siteryn_mcsc_get_cart_stateRead-only, no nonce
siteryn_mcsc_pro_apply_coupon · _remove_coupon Procoupon_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

See the Hooks reference for every action and filter.