• Resolved studioexcel

    (@studioexcel)


    Hello,
    What’s the best way to obtain the list of products on the wishlist in PHP?
    I’m using the free version of the plugin and I need to introduce custom functionality for the client.
    I need to obtain the list of products (only product names) added to the wishlist on the Wishlist page.
    I would really appreciate it if you could point me to a class or function in the plugin code I could use for this purpose.
    Many thanks,
    Jack

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

    (@yithemes)

    Hi Jack

    Here a snippet of code that could work for you

    $products         = array();
    	$default_wishlist = YITH_WCWL_Wishlist_Factory::get_default_wishlist();
    
    	if ( $default_wishlist ) {
    		$items = $default_wishlist->get_items();
    
    		if ( ! empty( $items ) ) {
    			foreach ( $items as $item ) {
    				$products[] = $item->get_product()->get_title();
    			}
    		}
    	}
    

    In the end you’ll have an array containing titles for products in default wishlist for current user, inside $products variable

    Thread Starter studioexcel

    (@studioexcel)

    Worked like a charm!
    Thank you very much for your prompt answer.
    Much appreciated!

    • This reply was modified 3 years, 8 months ago by studioexcel.
    Plugin Author YITHEMES

    (@yithemes)

    You’re welcome!

    We are doing our best to improve our plugins. Our target is to develop and release the best free plugins for WooCommerce, but to achieve this we need your help. Please leave a good review to support us and help our growth

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get products on wishlist in PHP’ is closed to new replies.