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']);
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!