• Resolved bababoom

    (@bababoom)


    Hello!

    On a simple product when we click on the checkbox to specify if a product is downloadable & virtual, the shipping tab is hiding, that prevent the shipping step to appears during the checkout.

    The problem is I have downloadable virtual product with variations, when clicking those checkbox, the shipping tab remains and the shipping step is displayed during the checkout.

    Is there a way to remove the shipping step completely for variable virtual products?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @bababoom,

    You can set the actual variation itself to Virtual and Downloadable and that should do it! ??

    Example:
    https://a.mikey.link/3VZbVl

    Thread Starter bababoom

    (@bababoom)

    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;
    }

    Hi @bababoom,

    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.

    I wonder if this has to do with a plugin or your theme maybe? What happens if you disable all your custom code, switch to a default theme like Twenty Seventeen, and disable all plugins except WooCommerce?

    Thread Starter bababoom

    (@bababoom)

    Hi Mikey,

    Indeed, just by removing my multi-step checkout plugin (by RedNumber) the checkout will remove the shipping step..

    I told plugin’s author to fix that!

    Thanks for your time ??

    Hi @@bababoom,

    Indeed, just by removing my multi-step checkout plugin (by RedNumber) the checkout will remove the shipping step..

    Good call! Happy you figured it out ??

    Cheers,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Skip Shipping for Virtual Variable products’ is closed to new replies.