• Hi,

    is there a way to automatically remove product from the wishlist when the product was purchased by adding straight to the basket outside of the wishlist, please?

    Many thanks
    Marcin

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

    (@yithemes)

    Hi Marcin

    Unfortunately our plugin doesn’t have this option currently
    You could remove the product immediately after it has been added to cart from the wishlist, using “Remove if added to the cart” option, under WP Dashboard -> YITH -> Wishlist -> Wishlist Page Options -> Wishlist detail page

    Otherwise, if you want a more “gift-list” behaviour, I suggest you to check this topic on our knowledgbase

    Please, note that it still needs to be update to properly work with wishlist 3.x
    I’m attaching to this answer the update code

    if( defined( 'YITH_WCWL' ) ){
    	if( ! function_exists( 'yith_wcwl_set_visited_wishlist_cookie' ) ) {
    		function yith_wcwl_set_visited_wishlist_cookie() {
    		    $wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist();
    
    		    if( ! $wishlist ){
    		        return;
                }
    
    		    if( $wishlist->is_current_user_owner() ){
    		    	return;
    		    }
    
    			wc_setcookie( 'yith_wcwl_visited_wishlist', $wishlist->get_id(), time() + apply_filters( 'yith_wcwl_cookie_expiration', 60 * 60 * 24 * 30 ), false );
    		}
    
    		add_action( 'template_redirect', 'yith_wcwl_set_visited_wishlist_cookie', 10 );
    	}
    
    	if( ! function_exists( 'yith_wcwl_set_visited_wishlist_order_meta' ) ){
    		function yith_wcwl_set_visited_wishlist_order_meta( $order_id ){
    			$visited_wishlist = $_COOKIE['yith_wcwl_visited_wishlist'];
    
    			update_post_meta( $order_id, '_yith_wcwl_visited_wishlist', $visited_wishlist );
    			wc_setcookie( 'yith_wcwl_visited_wishlist', '', time() - 3600 , false );
    		}
    		add_action( 'woocommerce_checkout_update_order_meta', 'yith_wcwl_set_visited_wishlist_order_meta', 10, 1 );
    	}
    
    	if( ! function_exists( 'yith_wcwl_delete_wishlist_item' ) ){
    		function yith_wcwl_delete_wishlist_item( $order_id ){
    			$visited_wishlist = get_post_meta( $order_id, '_yith_wcwl_visited_wishlist', true);
    
    			if( ! empty( $visited_wishlist ) ) {
    				$wishlist = yith_wcwl_get_wishlist( $visited_wishlist );
    				$order = wc_get_order( $order_id );
    
    				if( $wishlist && $order ){
    					$items = $order->get_items();
    
    					if( ! empty( $items ) ){
    						foreach ( $items as $item ){
    							$prod_id = $item['product_id'];
    							$wishlist->remove_product( $prod_id );
    						}
    
    						$wishlist->save();
    					}
    				}
    			}
    
    			delete_post_meta( $order_id, '_yith_wcwl_visited_wishlist' );
    		}
    		add_action( 'woocommerce_order_status_completed', 'yith_wcwl_delete_wishlist_item', 10, 1 );
    	}
    }
    

    Maybe you could give it a try and see if it works as you wish ??

    Thread Starter michu0000

    (@michu0000)

    Thank you, I will give it a try.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Removing product from wishlist after purchase’ is closed to new replies.