Woocommerce update fragments in multiple divs
-
I’m using the following code to display different image based on the condition whether the cart is empty or not.
add_filter( 'woocommerce_add_to_cart_fragments', 'custom_happy_sad_thumb' ); function 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 want to have similar functionality in the footer also, the only difference is there the div class name is ‘footer-left’, so would I need to rewrite this code again in functions.php? or can I just add the class name in $fragments array? Like this: $fragments[‘.sad’, ‘footer-left’]
Thanks in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Woocommerce update fragments in multiple divs’ is closed to new replies.