• Resolved aecorn

    (@aecorn)


    It seems the array that contains the $favourites does not clean up products no longer in the store. So that the if-statement
    if(!empty($favourites))
    Will return as not empty, even though the list is empty. If the product was favourited before it was removed…

    Im not exactly sure how to hack this. Maybe I need to add a for-loop that check through all products to see if they are in stock…

    Any better ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter aecorn

    (@aecorn)

    Hm, found a solution using is_in_stock, but this requires the manager to set products to out of stock before throwing them away :/

    function simple_print_favourites( $atts ){
    	$GLOBALS['simple_favourites_running'] = true;
    	extract( shortcode_atts( array(
            'user_id' => false
        ), $atts ) );
    	$favourites = simple_favourites::get_favourites($user_id);
    	$stack = [];
    	/* check if product is in stock? */
    	
    	foreach ($favourites as $favs){
    		$_product = wc_get_product( $favs );
    		
    		if ($_product->is_in_stock()) {
    			array_push($stack, $favs);
    		}
    	}
    			
    	$fav_output = '';
    	if(!empty($stack)) :
    		$fav_list = do_shortcode('[products ids="' . implode(',', $favourites) . '" columns="4"]');
    		$fav_output = "<style> .fav-tittel { display: inherit !important;}</style><div id='simple_favourites_display'>" . $fav_list . "</div>";
    		/*var_dump ($stack);*/
    return $fav_output;
    	endif;
    	unset($GLOBALS['simple_favourites_running']);
    Plugin Author Jon Boss

    (@jonboss)

    Hey @aecorn,

    I realize this one is a little old, but better late than never!

    Thanks so much for your posts here – I apologize for taking some time to make these changes, but this was great insight. The issue is – the plugin does actually clean up the $favourites array, but products that are still in the trash – while not shown, still exist – and so if ONLY trashed products were in the array, the shortcode showed a blank page. I’ve updated this in 1.4, thanks for your help.

    Thread Starter aecorn

    (@aecorn)

    Yeah, seems I was a bit bad at explaining exactly what I was doing to achieve the issue, but seems like you figured it out.
    Thank you for being responsive!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Removed products still in array’ is closed to new replies.