I am utilizing the next code to show totally different picture primarily based on the situation whether or not the cart is empty or not.
add_filter( 'woocommerce_add_to_cart_fragments', 'custom_happy_sad_thumb' );
operate custom_happy_sad_thumb( $fragments ) {
ob_start();
$cart_count = WC()->cart->cart_contents_count;
?>
<div class="sad">
<?php
if ( $cart_count > 0 ) { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/img/happy.png" alt="">
<?php }
else { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/img/sad.png" alt="">
<?php } ?>
</div>
<?php
$fragments['.sad'] = ob_get_clean();
return $fragments;
}
Now, I wish to have comparable performance within the footer additionally, the one distinction is there the div class title is ‘footer-left’, so would I have to rewrite this code once more in features.php? or can I simply add the category title in $fragments array? Like this: $fragments[‘.sad’, ‘footer-left’]
Thanks upfront.