4

I'm using the Drupal Commerce module with Shipping 7.x-1.0. I created a webshop with both real and virtual products.

My problem is that the shipping address is required even if all the products are virtual (so there is no shipping). How can I make sure that the shipping address is only asked for if the shoppingcart contains real products?

1

2 Answers 2

3

Here's a solution that doesn't require a custom module:

  • Install Commerce Rules Extra
  • Create a rule for Event: Process checkout pane
  • Add Action: Change pane properties
    • Value: Shipping information
    • Page to move to: <do not change>
    • Enabled: uncheck
  • Add Condition: e.g. by Order contains products of particular product types, or based on Commerce order contains shippable products supplied by Commerce Physical Product.

You may have to clear caches before this takes effect.

1
  • There is no rule like "Process checkout pane". The rule is named "Process change to a checkout pane".
    – Kevin Siji
    Aug 6, 2015 at 4:23
5

you could use hook_commerce_checkout_pane_info_alter and do

unset($checkout_pane['customer_profile_shipping']);

only if all line_items contains physical products:

function mymodule_commerce_checkout_pane_info_alter(&$checkout_pane) {
  global $user;

  foreach ($checkout_pane as $pane_name => & $pane_data) {
    if ($pane_name == 'customer_profile_shipping') {
      $order = commerce_cart_order_load($user->uid);
     if ($order) {
       $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
       $lines = $order_wrapper->commerce_line_items->value();

       $ask_shipping = FALSE;
       foreach ($lines as $line) {
         if ($line->type == 'product') {
           $line_wrapper = entity_metadata_wrapper('commerce_line_item', $line);
           $product = $line_wrapper->commerce_product->value();
           if ($product->type == '---> you physical product type <---') {
             $ask_shipping = TRUE;
           }
         }
       }

       if (!$ask_shipping) {
         unset($checkout_pane['customer_profile_shipping']);
       }
     }
   }
 }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.