• Resolved Vipworks

    (@pooja_gajrani)


    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)
  • Mirko P.

    (@rainfallnixfig)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

Viewing 1 replies (of 1 total)
  • The topic ‘Woocommerce update fragments in multiple divs’ is closed to new replies.