autora lab

Cart Share developer hooks

Cart Share has four filters for the link and the share buttons, one action for when a shared cart loads, and a way to add your own share app.

Add these snippets to a small custom plugin or to your child theme's functions.php.

The link format

{base}?products=ID:QTY,ID:QTY&coupon=CODE,CODE

For a variable product, the ID is the variation's ID. The base is WooCommerce's /checkout-link/ address on version 10 and newer, or your cart page.

Filters

Filter and argumentsChanges
alcartshare_base_url
string $base_url
The address every link starts with.
alcartshare_url
string $share_url, array $context
The finished link. $context holds products (the products value) and coupons.
alcartshare_text
string $share_text
The message sent with the link. By default, “Check out my shopping cart!”
alcartshare_social_links
array $links, string $share_url, string $share_text
The share buttons in the popup, keyed by app, each with a url, label and icon.

This example changes the share message:

add_filter( 'alcartshare_text', function () {
	return 'Here is my cart from Good Ideas Studio:';
} );

Action: alcartshare_processed

Runs after Cart Share fills a cart from a link that opens on the cart page. It gets the items as array $items. Links that open at WooCommerce's own checkout are handled by WooCommerce, so this action doesn't run for them.

Add your own share app

Write a class that implements AlCartShare\SocialMedia\ShareProvider, then register it with ShareProviderFactory::register(). Apps you add are always on and have no checkbox in the settings.

<?php
// class-my-line-share.php

use AlCartShare\SocialMedia\ShareProvider;

class My_Line_Share implements ShareProvider {
	public function generate_share_url( string $url, string $text ): string {
		return 'https://social-plugins.line.me/lineit/share?url=' . rawurlencode( $url );
	}

	public function get_label(): string {
		return 'LINE';
	}

	public function get_icon(): string {
		return '<svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor">...</svg>';
	}

	public function get_name(): string {
		return 'line';
	}
}
add_action( 'init', function () {
	if ( ! interface_exists( \AlCartShare\SocialMedia\ShareProvider::class ) ) {
		return; // Cart Share isn't active.
	}

	require_once __DIR__ . '/class-my-line-share.php';
	\AlCartShare\SocialMedia\ShareProviderFactory::register( 'line', My_Line_Share::class );
} );

get_icon() returns inline SVG markup. Use currentColor so the icon matches the other buttons.