Hide shipping if free shipping

WCMp Core

Hide shipping if free shipping Open

Viewing 7 reply threads
  • Author
    Posts
    • #78752
      kim
      Participant

      Hi there

      It’s a little bit silly, that if a customer buy so they get free shippinh, the standard shipping price is still chosen. Can’t you hide the other shipping price, or just change the chosen shipping method to free?

    • #78771

      Hi Kim, you can hide other shipping methods if free shipping is applied. For this please follow this thread – https://wc-marketplace.com/support-forum/topic/hide-flat-rate-shipping-method-when-free-shipping-is-enabled/#post-56722

    • #78777
      kim
      Participant

      I have added the code in my function.php

      /**
       * Hide others shipping when free shipping is available.
       */
      function hide_shipping_when_free_is_available( $rates ) {
          $free = array();
          foreach ( $rates as $rate_id => $rate ) {
                  if ( 'free_shipping' === $rate->method_id ) {
                          $free[ $rate_id ] = $rate;
                          break;
                  }
          }
          return ! empty( $free ) ? $free : $rates;
      }
      add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100 );

      Clear your WooCommerce cache. Go to WooCommerce > System Status > Tools > WC Transients > Clear transients.

      No luck. The free shipping is setup in the vendors system – NOT in the WooCommerce settings.

    • #78935
      sumit singh
      Moderator

      Hi, use this modified code.

      function hide_shipping_when_free_is_available( $rates ) {
          $free = array();
          foreach ( $rates as $rate_id => $rate ) {
                  if ( 'Free shipping' === $rate->label ) {
                          $free[ $rate_id ] = $rate;
                          break;
                  }
          }
          return ! empty( $free ) ? $free : $rates;
      }
      add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100 );
    • #78937
      kim
      Participant

      Sorry but still the same.

    • #78943

      @kim, I have checked this on our end, didn’t face any issue: https://www.loom.com/share/c76dd7007a5a45fc851bda1a3f9592d6

      So, please Clear your WooCommerce cache by navigating to WooCommerce > System Status > Tools > WC Transients > Clear transients.

    • #78944
      kim
      Participant

      Ah…. the problem is in your label, you are using the english term “Free shipping”, but here in Denmark, it’s called “Gratis forsendelse”.

      Thanks, now it’s working.

    • #78945
      This reply has been marked as private.
Viewing 7 reply threads

Please LOGIN to reply to this topic