• Hi,

    I would like to apply some custom code for variable products.

    To do this, I need to know if the variation_id exist in the wishlist on the found_variation event.

    Do you have any idea how I can check if a specific ID exist in the wishlist using JS ?

    Thank you very much.

    Anthony

    • This topic was modified 4 years, 6 months ago by nartoof.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nartoof

    (@nartoof)

    I finally fint it by myself using :

    $wishlist = YITH_WCWL()->get_products( [ 'wishlist_id' => 'all' , 'user_id' => get_current_user_id() ] );

    Plugin Author YITHEMES

    (@yithemes)

    Hi there

    I’m glad to know you worked around the problem, even if I must confess I’m not totally sure the code you pasted is really related to the issue

    You cannot check if a product is in wishlist on js, you’ll need a custom ajax call, and I’d suggest doing this with the following code

    $product_id = 123;
    $in_wishlist = false;
    $default_wishlist = YITH_WCWL_Wishlist_Factory::get_default_wishlist();
    
    if( $default_wishlist ) {
    	$in_wishlist = $default_wishlist->has_product( $product_id );
    }
    
    Thread Starter nartoof

    (@nartoof)

    Hi @yithemes,

    Thank you for your answer who is better than mine.
    But actually my solution doesn’t need AJAX call so it is a little bit faster.

    If I’m right, my $wishlist variable return an object with all items in the current user wishlist ?

    Then I loop the variable to get all ID’s in a string.

    I pass this variable to Javascript with my own script using a hook on single product page, then I can check onclick if the variation ID is in my ID’s list.

    I wanted to know all ID’s to let user add or remove a variation from the single product page with AJAX (because in your free version, we can’t add the parent and several variations to the wishlist).

    Plugin Author YITHEMES

    (@yithemes)

    Hi again

    Sorry for the delay in my answer, your last reply went under my radar
    So, I understand your approach, and it seems fine to me; I just wanted to warn you about the problems that cache could cause with this system (for this reason usually ajax is better)

    because in your free version, we can’t add the parent and several variations to the wishlist

    Well, that’s not correct; you should be able to add both parent product and as many variations as you wish
    But anyway, I’m glad to know that you worked your problem around ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Check if variation exist in wishlist on found_variation event’ is closed to new replies.