Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi there

    you can use yith_wcwl_added_to_wishlist; this hook will pass the following data

    • ID of the product being added
    • Brand new wishlist item
    • User id (if any)

    Hope this helps

    Thread Starter andersi913

    (@andersi913)

    Thanks that helped!
    Do you have a similar hook to when product is removed from wishlist?

    I still got some problems i want to add a value to a product attribute when it is added to wishlist for certain user roles..

    I got this code:

    
    add_action('yith_wcwl_added_to_wishlist', 'addOwnedByUserToProduct', 10, 3); 
    
    function addOwnedByUserToProduct($product_id, $wishlist_id, $user_id) {
        if(!is_user_logged_in()) {		
        	return;
        }
    	
    	$user = wp_get_current_user(); 
    	$roles = ( array ) $user->roles;
        
    	foreach ($roles as $role) {
    		if($role == 'medlem' || $role == 'administrator' || $role == 'bestyrelse') {
                // add username as value to product attribute named "i eje" not really sure how to
    			
    			break;
            }
        }
    }
    

    But i cant figure out how to add/append a value to the product attribute “i eje”..

    I know it is not your problem but thanks for the help with the hook.. ??

    Plugin Author YITHEMES

    (@yithemes)

    Hi again

    Do you have a similar hook to when product is removed from wishlist?

    Yes: yith_wcwl_removed_from_wishlist
    It will pass same attributes as the previous hook (please, note that in my last answer I incorrectly stated that second parameter is a wishlist item, while it is wishlist id; I’m sorry for the confusion)

    But i cant figure out how to add/append a value to the product attribute “i eje”..

    You can proceed this way

    $product = wc_get_product( $product_id );
    
    if ( $product ) {
        $i_eje = (array) $product->get_meta( 'i_eje' );
    
        if ( ! in_array( $user->user_login, $i_eje ) ) {
            $i_eje[] = $user->user_login;
        }
    
        $product->update_meta_data( 'i_eje', $i_eje );
        $product->save();
    }
    

    Hope this helps

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add action after product added to wishlist’ is closed to new replies.