get_wishlist_url();
}
/**
* Get wishlist count
*/
function airy_wishlist_get_count() {
$data = Airy_Wishlist_Data::instance();
return $data->get_count();
}
/**
* Get a public, shareable URL for the current user's wishlist.
*
* @return string Shareable URL.
*/
function airy_wishlist_get_share_url() {
$data = Airy_Wishlist_Data::instance();
return $data->get_share_url();
}
/**
* Check if product is in wishlist
*
* @param int $product_id Product ID to check.
* @param int $variation_id Optional variation ID.
* @return bool True if product is in wishlist.
*/
function airy_wishlist_is_product_in_wishlist( $product_id, $variation_id = 0 ) {
$data = Airy_Wishlist_Data::instance();
return $data->is_in_wishlist( $product_id, $variation_id );
}
/**
* Get add to wishlist button HTML
*
* @param int $product_id Product ID.
* @param string $context Display context - 'single' or 'loop'.
* @return string Button HTML.
*/
function airy_wishlist_get_button_html( $product_id, $context = 'single' ) {
// Hide the button entirely for guests when guest wishlists are disabled.
if ( ! Airy_Wishlist_Data::instance()->is_enabled_for_visitor() ) {
return '';
}
$product = wc_get_product( $product_id );
if ( ! $product ) {
return '';
}
// For variable products in loop, don't show button (needs variation selection).
if ( 'loop' === $context && $product->is_type( 'variable' ) ) {
return '';
}
// For grouped products, don't show button (complex logic).
if ( $product->is_type( 'grouped' ) ) {
return '';
}
$data = Airy_Wishlist_Data::instance();
$in_wishlist = $data->is_in_wishlist( $product_id );
$button_type = get_option( 'airy_wishlist_button_type', 'icon_text' );
$icon = get_option( 'airy_wishlist_button_icon', 'heart' );
$add_text = get_option( 'airy_wishlist_add_button_text', __( 'Add to Wishlist', 'airy-wishlist' ) );
$added_text = get_option( 'airy_wishlist_added_button_text', __( 'Added to Wishlist', 'airy-wishlist' ) );
$classes = array( 'airy-wishlist-btn' );
if ( $in_wishlist ) {
$classes[] = 'added';
}
// For variable products, add disabled state initially.
$is_variable = 'single' === $context && $product->is_type( 'variable' );
$button_style = '';
$button_disabled = '';
if ( $is_variable ) {
$button_style = ' style="display:none;"'; // Hide initially.
$button_disabled = ' disabled="disabled"'; // Also disable.
$classes[] = 'airy-variable-disabled';
}
$button_html = '
';
$button_html .= '';
$button_html .= '
';
return apply_filters( 'airy_wishlist_button_html', $button_html, $product_id, $in_wishlist );
}
/**
* Get icon SVG
*
* @param string $icon Icon type - 'heart', 'star', or 'bookmark'.
* @return string SVG HTML.
*/
function airy_wishlist_get_icon( $icon = 'heart' ) {
$icons = array(
'heart' => '',
'star' => '',
'bookmark' => '',
);
return isset( $icons[ $icon ] ) ? $icons[ $icon ] : $icons['heart'];
}
/**
* Escape SVG output - allows SVG tags that wp_kses_post strips
*
* @param string $svg SVG HTML to escape.
* @return string Escaped SVG HTML.
*/
function airy_wishlist_kses_svg( $svg ) {
$allowed_tags = array(
'svg' => array(
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'fill' => true,
'stroke' => true,
'stroke-width' => true,
'stroke-linecap' => true,
'stroke-linejoin' => true,
'class' => true,
),
'path' => array(
'd' => true,
'fill' => true,
'stroke' => true,
),
'polygon' => array(
'points' => true,
'fill' => true,
'stroke' => true,
),
'circle' => array(
'cx' => true,
'cy' => true,
'r' => true,
'fill' => true,
'stroke' => true,
),
'rect' => array(
'x' => true,
'y' => true,
'width' => true,
'height' => true,
'fill' => true,
'stroke' => true,
),
'line' => array(
'x1' => true,
'y1' => true,
'x2' => true,
'y2' => true,
'stroke' => true,
),
'g' => array(
'fill' => true,
'stroke' => true,
),
);
return wp_kses( $svg, $allowed_tags );
}
/**
* Escape button HTML with SVG support
*
* @param string $html Button HTML to escape.
* @return string Escaped button HTML.
*/
function airy_wishlist_kses_button( $html ) {
$allowed_tags = array(
'div' => array(
'class' => true,
'style' => true,
),
'button' => array(
'type' => true,
'class' => true,
'data-product-id' => true,
'data-variation-id' => true,
'data-is-variable' => true,
'disabled' => true,
),
'span' => array(
'class' => true,
),
'svg' => array(
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'fill' => true,
'stroke' => true,
'stroke-width' => true,
'stroke-linecap' => true,
'stroke-linejoin' => true,
'class' => true,
),
'path' => array(
'd' => true,
'fill' => true,
'stroke' => true,
),
'polygon' => array(
'points' => true,
'fill' => true,
'stroke' => true,
),
'circle' => array(
'cx' => true,
'cy' => true,
'r' => true,
'fill' => true,
'stroke' => true,
),
);
return wp_kses( $html, $allowed_tags );
}
/**
* Add product to wishlist
*
* @param int $product_id Product ID to add.
* @param int $variation_id Optional variation ID.
* @return bool True if added successfully.
*/
function airy_wishlist_add_product( $product_id, $variation_id = 0 ) {
$data = Airy_Wishlist_Data::instance();
return $data->add_to_wishlist( $product_id, $variation_id );
}
/**
* Remove product from wishlist
*
* @param int $product_id Product ID to remove.
* @param int $variation_id Optional variation ID.
* @return bool True if removed successfully.
*/
function airy_wishlist_remove_product( $product_id, $variation_id = 0 ) {
$data = Airy_Wishlist_Data::instance();
return $data->remove_from_wishlist( $product_id, $variation_id );
}
/**
* Get wishlist items
*/
function airy_wishlist_get_items() {
$data = Airy_Wishlist_Data::instance();
return $data->get_items();
}
/**
* Clear wishlist
*/
function airy_wishlist_clear() {
$data = Airy_Wishlist_Data::instance();
return $data->clear_wishlist();
}