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?– Valdeir Psr
@Thank you, but I don’t understand!
– b8engl