Hi,
there is no redirect after clicking on the button wishlist. When this happens?
Hi, thanks for your reply.
I’m using cheope theme and I’m trying to implement it manualy.. so i create an icon with similar following link:
http://www.nnn.pt/wp-content/themes/cheope/theme/plugins/yith_wishlist/yith-wcwl-ajax.php?action=add_to_wishlist&add_to_wishlist=128099
And if i click it he redirects to product page.
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' );
Hi,
Thanks for your reply and the code that works very well 🙂
Now i only need to remove the redirection, for example, in product list page if i add one product to wishlist without how can i do without leaving this product list page, is it possible?
Hi again 🙂
Try using this url:
$url = add_query_arg( 'add_to_wishlist', $product->id );
This should add to wishlist, and redirect to the same page.
It would take a lot more work to get the same result asynchronously; in this case you should use the shortcode [yith_wcwl_add_to_wishlist]
echo do_shortcode( '[yith_wcwl_add_to_wishlist]' );
making sure that the global variable $product is correctly set, and customizing the template through the filters provided
Perfect 🙂
Thanks for your time, five stars!