"Move to Wishlist from Cart Button" Snippet
Read this article to learn more about the snippet usage.
Usage:
{% render 'wl-move-to-wishlist' %}
Code:
{% comment %}
wl-move-to-wishlist
"Move to wishlist" button for cart line items: adds the line's variant to the
wishlist, then removes the line from the cart.
Requires
- Wishlist app installed
- App embeds → Wishlist helper enabled (handles clicks; no JS in this file)
Styles ship inside this snippet, so the button looks correct even if the
helper is off — but clicks will not work without the helper.
Setup
1. Online Store → Themes → Edit code → Snippets → Add a new snippet.
2. Name it wl-move-to-wishlist and paste this file.
3. Render it inside the cart line item loop (cart page and/or cart drawer).
Examples
Cart page / cart drawer (default `after_move: 'auto'` — the theme's own
remove button of this line is used, so the cart updates the same way as
a regular remove, without a page reload):
{% for item in cart.items %}
...
{% render 'wl-move-to-wishlist', item: item %}
{% endfor %}
Custom theme with a non-standard remove button:
{% render 'wl-move-to-wishlist', item: item, remove_selector: '.js-line-remove' %}
Re-render cart sections yourself (theme has no remove button in the line):
{% render 'wl-move-to-wishlist',
item: item,
after_move: 'sections',
refresh_sections: 'main-cart-items,cart-icon-bubble,cart-live-region-text,main-cart-footer'
%}
Template sections have dynamic ids — pass them from Liquid, e.g.
refresh_sections: section.id (comma-separated if several).
Text link look:
{% render 'wl-move-to-wishlist', item: item, view: 'text_only', text_underline: true, text_size: 13 %}
Icon + text, bordered button:
{% render 'wl-move-to-wishlist',
item: item,
view: 'icon_and_text',
button_border: true,
button_border_radius: 4,
button_padding_x: 12,
button_padding_y: 8,
button_bg_color: '#ffffff'
%}
Theme handles the update itself (listen to the event, see Notes):
{% render 'wl-move-to-wishlist', item: item, after_move: 'event' %}
Parameters
item Cart line item. Required.
visibility everyone (default) | logged_in_only
view icon_and_text (default) | icon_only | text_only
icon_position start (default) | end Icon before / after the label
content_align left (default) | center | right
label Custom label. Default: theme translation (see Notes)
loading_label Label while moving. Default: theme translation (see Notes)
show_popup "Added to wishlist" toast. Default: true
Not visible when the page reloads.
after_move auto (default) | sections | reload | event
auto – click the theme's remove button of this line
(theme updates the cart itself, no reload);
if none is found → `sections` when
`refresh_sections` is set, otherwise reload
sections – remove via /cart/change.js and re-render
`refresh_sections` (Section Rendering API);
reload if none of them is on the page
reload – remove via /cart/change.js, then reload
event – remove via /cart/change.js, only dispatch
`wishlist:cart-item-moved`
remove_selector CSS selector of the theme's line remove button (auto mode).
Default covers common themes: cart-remove-button (Dawn and
Dawn-based), [data-cart-remove], [data-remove-item],
.cart-item__remove, .cart-remove, a[href*="quantity=0"]
refresh_sections Comma-separated section ids for after_move: 'sections'
(also used by auto as a fallback).
icon_color Default: currentColor
icon_size Desktop icon size, px. Default: 18
icon_size_mobile Mobile icon size, px. Default: 18
text_color Default: currentColor
text_size Desktop label size, px. Default: 14
text_size_mobile Mobile label size, px. Default: 14
text_weight CSS font-weight. Default: inherit
text_underline Underline the label. Default: false
text_transform none (default) | uppercase | lowercase | capitalize
icon_text_gap Gap between icon and label, px. Default: 6
hover_opacity Opacity on hover, 0–1. Default: 0.7
margin_top px. Default: 0
margin_right px. Default: 0
margin_bottom px. Default: 0
margin_left px. Default: 0
max_width px. 0 = no limit. Default: 0
full_width Button stretches to the container width. Default: false
button_bg_color Default: transparent
button_border Show border. Default: false
button_border_color Default: #000000
button_border_width px. Default: 1
button_border_radius px. Default: 0
button_padding_x px. Default: 0
button_padding_y px. Default: 0
Notes
- Labels use theme translations (English fallback if missing):
wishlist.move_to_wishlist "Move to wishlist"
wishlist.moving "Moving…"
- Flow: add to wishlist (default list, or the list picker when multiple
wishlists are on) → wait until it is saved → remove the line (theme's
remove button, or /cart/change.js by line key). If the add fails, the
cart is not touched. Already in the wishlist → the line is just removed.
- After every successful move `wishlist:cart-item-moved` is dispatched on
`document` with detail { key, productId, variantId, cart, sections, via }.
`via` is 'theme' | 'cart-change'; `cart` / `sections` are null for 'theme'.
- Theme editor: the button renders but clicks are ignored.
{% endcomment %}
{% liquid
assign is_blocked = shop.metafields.wishlist.app_blocked
assign visibility = visibility | default: 'everyone'
assign show_snippet = true
unless request.design_mode or customer
if visibility == 'logged_in_only'
assign show_snippet = false
endif
endunless
assign view = view | default: 'icon_and_text'
assign icon_position = icon_position | default: 'start'
assign content_align = content_align | default: 'left'
assign show_popup = show_popup | default: true, allow_false: true
assign after_move = after_move | default: 'auto'
assign refresh_sections = refresh_sections | default: ''
assign remove_selector = remove_selector | default: ''
assign icon_color = icon_color | default: 'currentColor'
assign icon_size = icon_size | default: 18
assign icon_size_mobile = icon_size_mobile | default: 18
assign text_color = text_color | default: 'currentColor'
assign text_size = text_size | default: 14
assign text_size_mobile = text_size_mobile | default: 14
assign text_weight = text_weight | default: 'inherit'
assign text_underline = text_underline | default: false
assign text_transform = text_transform | default: 'none'
assign icon_text_gap = icon_text_gap | default: 6
assign hover_opacity = hover_opacity | default: 0.7
assign margin_top = margin_top | default: 0
assign margin_right = margin_right | default: 0
assign margin_bottom = margin_bottom | default: 0
assign margin_left = margin_left | default: 0
assign max_width = max_width | default: 0 | plus: 0
assign full_width = full_width | default: false
assign button_bg_color = button_bg_color | default: 'transparent'
assign button_border = button_border | default: false
assign button_border_color = button_border_color | default: '#000000'
assign button_border_width = button_border_width | default: 1
assign button_border_radius = button_border_radius | default: 0
assign button_padding_x = button_padding_x | default: 0
assign button_padding_y = button_padding_y | default: 0
assign show_icon = true
assign show_text = true
if view == 'icon_only'
assign show_text = false
elsif view == 'text_only'
assign show_icon = false
endif
assign align_class = 'wl-move--align-left'
if content_align == 'right'
assign align_class = 'wl-move--align-right'
elsif content_align == 'center'
assign align_class = 'wl-move--align-center'
endif
assign modifier_classes = align_class
if icon_position == 'end'
assign modifier_classes = modifier_classes | append: ' wl-move--icon-end'
endif
if full_width
assign modifier_classes = modifier_classes | append: ' wl-move--full'
endif
assign locale_code = request.locale.iso_code | split: '-' | first | strip
assign dir_value = 'ltr'
if locale_code == 'ar' or locale_code == 'he' or locale_code == 'fa' or locale_code == 'ur'
assign dir_value = 'rtl'
endif
assign text_move = label
if text_move == blank
assign text_move = 'wishlist.move_to_wishlist' | t
if text_move == 'wishlist.move_to_wishlist'
assign text_move = 'Move to wishlist'
endif
endif
assign text_loading = loading_label
if text_loading == blank
assign text_loading = 'wishlist.moving' | t
if text_loading == 'wishlist.moving'
assign text_loading = 'Moving…'
endif
endif
assign line_image = item.image | default: item.product.featured_image
%}
{% unless is_blocked or item == blank or show_snippet == false %}
<style>
.wl-move {
--wl-move-margin-top: 0;
--wl-move-margin-right: 0;
--wl-move-margin-bottom: 0;
--wl-move-margin-left: 0;
--wl-move-max-width: none;
--wl-move-gap: 6px;
--wl-move-font-size: 14px;
--wl-move-font-size-md: 14px;
--wl-move-font-weight: inherit;
--wl-move-text-color: currentColor;
--wl-move-text-decoration: none;
--wl-move-text-transform: none;
--wl-move-icon-color: currentColor;
--wl-move-icon-size: 18px;
--wl-move-icon-size-md: 18px;
--wl-move-hover-opacity: 0.7;
--wl-move-btn-bg: transparent;
--wl-move-btn-border: none;
--wl-move-btn-radius: 0;
--wl-move-btn-padding: 0;
display: flex;
box-sizing: border-box;
margin: var(--wl-move-margin-top) var(--wl-move-margin-right)
var(--wl-move-margin-bottom) var(--wl-move-margin-left);
width: 100%;
max-width: var(--wl-move-max-width);
user-select: none;
}
.wl-move--align-left {
justify-content: flex-start;
}
.wl-move--align-center {
justify-content: center;
}
.wl-move--align-right {
justify-content: flex-end;
}
.wl-move .wl-move__trigger {
display: inline-flex;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
gap: var(--wl-move-gap);
box-sizing: border-box;
cursor: pointer;
margin: 0;
border: var(--wl-move-btn-border);
border-radius: var(--wl-move-btn-radius);
background: var(--wl-move-btn-bg);
padding: var(--wl-move-btn-padding);
width: auto;
min-width: 0;
min-height: 0;
color: var(--wl-move-text-color);
font: inherit;
font-weight: var(--wl-move-font-weight);
font-size: var(--wl-move-font-size);
line-height: 1.2;
text-transform: var(--wl-move-text-transform);
letter-spacing: inherit;
transition: opacity 0.2s;
box-shadow: none;
-webkit-appearance: none;
appearance: none;
}
.wl-move--full .wl-move__trigger {
width: 100%;
}
.wl-move .wl-move__trigger:hover {
opacity: var(--wl-move-hover-opacity);
}
.wl-move .wl-move__trigger:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
.wl-move .wl-move__trigger[disabled] {
cursor: default;
opacity: 0.5;
}
.wl-move__media {
display: inline-flex;
flex-shrink: 0;
justify-content: center;
align-items: center;
width: var(--wl-move-icon-size);
height: var(--wl-move-icon-size);
color: var(--wl-move-icon-color);
}
.wl-move__media svg {
display: block;
width: 100%;
height: 100%;
}
.wl-move--icon-end .wl-move__media {
order: 1;
}
.wl-move__label {
min-width: 0;
text-decoration: var(--wl-move-text-decoration);
text-underline-offset: 2px;
white-space: nowrap;
}
.wl-move--loading .wl-move__media {
animation: wl-move-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes wl-move-pulse {
to {
opacity: 0.3;
}
}
@media (prefers-reduced-motion: reduce) {
.wl-move--loading .wl-move__media {
animation: none;
}
}
@media screen and (min-width: 768px) {
.wl-move .wl-move__trigger {
font-size: var(--wl-move-font-size-md);
}
.wl-move__media {
width: var(--wl-move-icon-size-md);
height: var(--wl-move-icon-size-md);
}
}
</style>
<wishlist-move-button
class='wl-move {{ modifier_classes }}'
data-wl-product-id='{{ item.product_id }}'
data-wl-variant-id='{{ item.variant_id }}'
data-wl-handle='{{ item.product.handle | escape }}'
data-wl-line-key='{{ item.key | escape }}'
data-wl-product-title='{{ item.product.title | escape }}'
{% if line_image != blank %}
data-wl-product-image='{{ line_image | image_url: width: 120 }}'
{% endif %}
{% unless show_popup %}
data-wl-skip-notification='true'
{% endunless %}
data-wl-after-move='{{ after_move | escape }}'
{% if refresh_sections != blank %}
data-wl-refresh-sections='{{ refresh_sections | escape }}'
{% endif %}
{% if remove_selector != blank %}
data-wl-remove-selector='{{ remove_selector | escape }}'
{% endif %}
data-wl-cart-change-url='{{ routes.cart_change_url }}.js'
dir='{{ dir_value }}'
style='
--wl-move-icon-color: {{ icon_color }};
--wl-move-icon-size: {{ icon_size_mobile }}px;
--wl-move-icon-size-md: {{ icon_size }}px;
--wl-move-text-color: {{ text_color }};
--wl-move-font-size: {{ text_size_mobile }}px;
--wl-move-font-size-md: {{ text_size }}px;
--wl-move-font-weight: {{ text_weight }};
--wl-move-text-transform: {{ text_transform }};
--wl-move-gap: {{ icon_text_gap }}px;
--wl-move-hover-opacity: {{ hover_opacity }};
--wl-move-margin-top: {{ margin_top }}px;
--wl-move-margin-right: {{ margin_right }}px;
--wl-move-margin-bottom: {{ margin_bottom }}px;
--wl-move-margin-left: {{ margin_left }}px;
--wl-move-btn-bg: {{ button_bg_color }};
--wl-move-btn-padding: {{ button_padding_y }}px {{ button_padding_x }}px;
{% if text_underline %}--wl-move-text-decoration: underline;{% endif %}
{% if max_width > 0 %}--wl-move-max-width: {{ max_width }}px;{% endif %}
{% if button_border %}--wl-move-btn-border: {{ button_border_width }}px solid {{ button_border_color }}; --wl-move-btn-radius: {{ button_border_radius }}px;{% endif %}
'
>
<button
type='button'
class='wl-move__trigger'
aria-label='{{ text_move | escape }}'
data-wl-label='{{ text_move | escape }}'
data-wl-label-loading='{{ text_loading | escape }}'
data-wl-move-trigger
>
{% if show_icon %}
<span class='wl-move__media' aria-hidden='true'>
<svg
xmlns='http://www.w3.org/2000/svg'
fill='none'
viewBox='0 0 24 24'
aria-hidden='true'
focusable='false'
>
<path
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='1.5'
d='M7.87891 3.75c.67013.00152 1.33423.14051 1.9541.40918.61989.26872 1.18439.66253 1.66019 1.16016.1399.14633.3336.22972.5361.23144.2024.00163.3967-.07878.5391-.22266.9658-.9764 2.2584-1.51357 3.5957-1.50488 1.3372.00873 2.6231.5627 3.5771 1.55176.955.98998 1.5 2.33576 1.5088 3.74707.0087 1.41133-.52 2.76473-1.4629 3.76753l-6.6318 6.877c-.3018.3128-.7055.4834-1.1201.4834-.4146-.0001-.8175-.1707-1.1192-.4834l-6.63963-6.8828-.00196-.0029-.17578-.1885c-.3984-.452-.71987-.9742-.94922-1.543-.26198-.6498-.39789-1.34784-.39941-2.0537-.0015-.70608.13124-1.40537.39062-2.05664.25939-.6512.64026-1.24084 1.11817-1.73633.47787-.49543 1.04403-.88648 1.66504-1.15234.62086-.26578 1.28506-.40188 1.95508-.40039'
/>
</svg>
</span>
{% endif %}
{% if show_text %}
<span class='wl-move__label' data-wl-move-label>
{{- text_move | escape -}}
</span>
{% endif %}
</button>
</wishlist-move-button>
{% endunless %}