• Hi,

    I am trying to use the plugin more like a favourite list. I have regular customers that normally buy the same items. The idea is to display the items they buy frequently using the plugin. My basket has an average of 20 SKU’s from a list of 500 SKUs listed on the website.

    Is it possible to add all the items purchased automatically to their own ‘wishlist/favourites’? So, next time they visit my shop those items will be displayed there. Maybe at the time of the purchase to do it? Or schedule to schedule a task?

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi there

    You could try to add the follwing code to functions.php file of your theme or child theme

    if ( ! function_exists( 'yith_wcwl_add_item_purchased_to_wishlist' ) ) {
    	function yith_wcwl_add_item_purchased_to_wishlist( $order_id, $order ) {
    		/**
    		 * @var $order WC_Order
    		 */
    		$customer_id = $order->get_customer_id();
    
    		if ( ! $customer_id ) {
    			return;
    		}
    
    		if ( ! function_exists( 'YITH_WCWL' ) ) {
    			return;
    		}
    
    		$customer_default_wishlist = YITH_WCWL_Wishlist_Factory::get_default_wishlist( $customer_id, 'edit' );
    
    		if ( ! $customer_default_wishlist ) {
    			return;
    		}
    
    		$items = $order->get_items( 'line_item' );
    
    		if ( empty( $items ) ) {
    			return;
    		}
    
    		foreach ( $items as $item ) {
    			/**
    			 * @var $item WC_Order_Item_Product
    			 */
    			$product_id = $item->get_product_id();
    			$variation_id = $item->get_variation_id();
    
    			$product_id = $variation_id ? $variation_id : $product_id;
    
    			if ( ! $product_id || $customer_default_wishlist->has_product( $product_id ) ) {
    				continue;
    			}
    
    			$customer_default_wishlist->add_product( $product_id );
    		}
    
    		$customer_default_wishlist->save();
    	}
    	add_action( 'woocommerce_order_status_completed', 'yith_wcwl_add_item_purchased_to_wishlist', 10, 2 );
    	add_action( 'woocommerce_order_status_processing', 'yith_wcwl_add_item_purchased_to_wishlist', 10, 2 );
    }
    

    When an order switches to completed or processing, this code will cycle through items, and add them to customer’s wishlist
    If no wishlist exists, one will be created for this purpose

Viewing 1 replies (of 1 total)
  • The topic ‘Wishlist / Favourite’ is closed to new replies.