Hi @mikeyarce,
That’s what I’ve done, both are checked, but when it’s the only product in the cart, the shipping step is still visible during the checkout.
Note that I’ve added those line of code in functions to remove the unwanted fields (of the billing step) when all the products in the cart are virtual, I don’t think it’s related though since my issue is with the shipping step of the checkout, therefore the shipping step that is still here is empty, customer need to click “NEXT” again:
/**
* woo remove fields virtual cart
*/
add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
/**
* Remove unwanted checkout fields
*
* @return $fields array
*/
function woo_remove_billing_checkout_fields( $fields ) {
if( woo_cart_virtual_downloadable_product_only() == true ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_phone']);
unset($fields['order']['order_comments']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_city']);
}
return $fields;
}
/**
* Check if the cart contains virtual/downloadable product only
*
* @return bool
*/
function woo_cart_virtual_downloadable_product_only() {
global $woocommerce;
// By default, virtual/downloadable product only
$virtual_downloadable_products_only = true;
// Get all products in cart
$products = $woocommerce->cart->get_cart();
// Loop through cart products
foreach( $products as $product ) {
// Get product ID
$product_id = $product['product_id'];
// is variation downloadable
$is_downloadable = $product['data']->downloadable;
// is variation virtual
$is_virtual = $product['data']->virtual ;
// Update $virtual_downloadable_products_only if product is not virtual or downloadable and exit loop
if( $is_virtual == 'no' && $is_downloadable == 'no' ){
$virtual_downloadable_products_only = false;
break;
}
}
return $virtual_downloadable_products_only;
}