# Wishlist Button – Implementation Details

## Overview

The "Add to Wishlist" button is rendered on WooCommerce single product pages and product loops. Its position on single product pages is configurable via the **Wishlist Button Position** setting in **Bizz Wishlist → Settings → General Settings**.

## Available Positions

| Setting Value | Description | WooCommerce Hook | Priority |
|---|---|---|---|
| `after_add_to_cart` | After the Add to Cart button (default) | `woocommerce_after_add_to_cart_button` | 10 |
| `before_add_to_cart` | Before the Add to Cart button | `woocommerce_before_add_to_cart_button` | 10 |
| `after_product_title` | After the product title | `woocommerce_single_product_summary` | 6 |
| `before_product_title` | Before the product title | `woocommerce_single_product_summary` | 4 |
| `custom_hook` | A user-defined hook name | User-specified | 10 |
| `none` | No automatic display | — | — |

## How It Works

### Single Product Pages

The `WishlistButton::render()` method is attached to a WooCommerce action hook based on the selected position. The hook registration happens in `Plugin::init_hooks()`:

- **After/Before Add to Cart**: Uses `woocommerce_after_add_to_cart_button` or `woocommerce_before_add_to_cart_button`.
- **After/Before Product Title**: Uses `woocommerce_single_product_summary` with priority `6` (after the title at priority `5`) or `4` (before the title).
- **Custom Hook**: The user enters a hook name in the settings. The button is attached to that action hook.
- **None**: No hook is registered. The button can still be displayed using the `[bizzwishlist_button]` shortcode or the `do_action('bizzwishlist_button')` action.

### Product Loops (Shop/Archive Pages)

The loop button is always rendered via the `woocommerce_loop_add_to_cart_link` filter, regardless of the position setting. This filter appends a compact wishlist icon button after the "Add to Cart" link in product grids.

## Shortcode & Action Hooks

Even when the position is set to **None**, the wishlist button can be manually placed using:

- **Shortcode**: `[bizzwishlist_button]` or `[bizzwishlist_button product_id="123"]`
- **PHP Action**: `do_action( 'bizzwishlist_button', $product_id )` or `do_action( 'bizzwishlist_button_show', $product_id )`

## Settings Storage

The position is stored in the `bizzwishlist_settings` option under the key `wishlist_button_position`. The custom hook name is stored under `wishlist_button_custom_hook`.

```php
// Retrieve the current position programmatically:
$position = \Bizzwishlist\Admin\Settings::get_wishlist_button_position();

// Retrieve the custom hook name:
$hook = \Bizzwishlist\Admin\Settings::get_wishlist_button_custom_hook();
```
