WooCommerce Checkout

I’m creating a plugin for WooCommerce to modify the Checkout page. I would like to do some conditional filters based on the users shopping cart. Is there a way to look at the items in the shopping cart, and determine if any of the items are NOT downloadable/virtual?

So far I have a filter and in the filter I want to hide the address fields. This works great, but now I want to make it conditional, and only hide the address fields if a non-downloadable product is included. Thanks

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
    $hasPhysicalProduct = 0;
    if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
        foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
            $_product = $values['data'];
            if ( SOMEHOW CHECK IF THE PRODUCT IS DOWNLOADABLE ) {
                $hasPhysicalProduct = 1;
            }
        }
    }

Related posts

Leave a Reply

1 comment