Support » Plugin: WooCommerce » Remove delivery option

  • Resolved craigmckee

    (@craigmckee)


    I have all my delivery criteria set up for local and national which is working well. But I want to remove all delivery options if my cart contains a certain product that cannot be delivered – even if it contains other things – is this possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • lorro

    (@lorro)

    You’ll need to cycle through the products in the cart and, if found, delete the inapplicable methods. Your code will look something like this. You’ll need the product id of the non-deliverable item, and the exact names fo your delivery methods. Be careful not to edit the delivery method names in future or the code will break. Some php skill will be needed. Sorry, can’t debug via the forum.

    add_filter( 'woocommerce_package_rates', 'custom_shipping_rates', 100, 2 );
    function custom_shipping_rates( $rates, $package ) {
    
      $cant_deliver_item_product_id = 69;
    
      foreach( $package['contents'] as $cart_item ) {
        if( $cart_item['product_id'] == $cant_deliver_item_product_id ) {
          foreach( $rates as $rate_id => $rate ) {
            if( 'Local Delivery' == $rate->label ) {
              unset( $rates[$rate_id] );
            }
            if( 'National Delivery' == $rate->label ) {
              unset( $rates[$rate_id] );
            }
          }
        }
      }
      return $rates;
    }
    Plugin Support gabrielfuentes

    (@gabrielfuentes)

    Hi @craigmckee 👋

    At the moment, there’s no default option for that in WooCommerce, and setting that as the default would require quite a bit of additional coding. Please kindly note that this requires some custom coding – which goes beyond the scope of support we are able to provide in this forum.

    Please feel free to follow @lorro great response and suggestion. 🙂

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    If you do require more help with the actual coding, we’d recommend you hire a developer who can take a look at this, quote you for their services, and help you add this feature to your site. We’d recommend getting in touch with a web developer or one of the customization experts listed at https://woocommerce.com/customizations/.

    Cheers!

    Thread Starter craigmckee

    (@craigmckee)

    @lorro many thanks – this is a bit above my skill level but I’ll have a play with that, thank you.

    @gabrielfuentes I appreciate the clarification, thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.