Check if cart is NOT empty Woocommerce 3.4+

Asked

Viewed 176 times

0

I intend to check if the cart is NOT empty, but I’m not getting it!
Can someone help me, please?

.

add_action( 'wp_footer', 'redirecionar' );
    function redirecionar(){
        global $woocommerce;
        if ( !sizeof($woocommerce->cart->cart_contents) ) {
           // hello_world
        }
}

..

add_action( 'wp_footer', 'vazio' );
    function vazio() {
        if ( ! WC()->cart->get_cart_contents_count() == 0 ) { 
           // hello_world
        }
}

...

add_action( 'wp_footer', 'vazio' );
    function vazio() {
        if ( ! WC()->cart->is_empty() ) { 
           // hello_world
         }
}

My code:

<?php add_action( 'wp_footer', 'vazio' );
    function vazio() {
        if ( ! WC()->cart->is_empty() ) { ?>
        <div style="width: 20%;" class="footer-section <?php echo esc_html($woo);?>">
            <a href="<?php echo 'https://my_web_page.pt/finalizar-compra';?>" title="Finalizar Compra"><i class="fa fa-credit-card"></i></a>
        </div>
    <?php   }
    } ?>
  • Use the method get_cart_contents_total. Has used var_dump( WC()->cart->get_cart_contents_count() ); to check the result?

  • @Thank you, but I don’t understand!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.