Hi calvares,
if you’re using wishlist 2.0 or higher, you can generate an url to wishlist page using the method get_wishlist_url() of class YITH_WCWL.
If you want your link to redirect to wishlist and, in the same time, to add a product to the wishlist, you can add to the url a query string like this: add_to_wishlist=<PRODUCT_ID>.
So, you can do something like this
$url = add_query_arg( 'add_to_wishlist', $product->id, YITH_WCWL()->get_wishlist_url() );
Assuming $product is the correct instance of WC_Product
For older version of wishlist, you’ll have to manually create your add_to_wishlist function; you can try using this url:
global $yith_wcwl;
$url = add_query_arg( 'add_to_wishlist', $product->id, $yith_wcwl->get_wishlist_url() );
and adding this custom function to your function.php file
if( ! function_exists( 'add_product_to_wishlist' ) ){
function add_product_to_wishlist(){
if( ! empty( $_GET['add_to_wishlist'] ) ){
global $yith_wcwl;
$yith_wcwl->add();
}
}
}
add_action( 'init', 'add_product_to_wishlist' );