How to Hide Woocommerce Shipping Methods with Shipping Classes?

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.ค. 2024
  • In this video I’m going to show you how to hide Woocommerce shipping methods with shipping classes. This allows you to hide specific shipping methods for specific shipping classes.
    All the snippets shown in the video are here: wpsimplehacks.com/how-to-hide...
    RELATED VIDEOS:
    How to Customize Woocommerce Admin Dashboard | 14 Simple Hacks • How to Customize Wooco...
    How to Customize Woocommerce Checkout Page Without a Plugin? 26 useful hacks • How to Customize Wooco...
    How to Customize Woocommerce Cart Page: 21 Cart page Hacks • How to Customize Wooco...
    How to Customize Woocommerce Category Page | 17+ Useful Hacks • How to Customize Wooco...
    How to Customize Woocommerce Single Product Page | 14 Useful Hacks • How to Customize Wooco...
    Blocksy and Kadence are currently two of the best WordPress themes. So, if you’re interested, then you can grab:
    🅱️ Blocksy theme wpsimplehacks.com/blocksy (SAVE 10% Coupon WPSH10)
    🔵 Kadence theme here: wpsimplehacks.com/kadence (SAVE 10% Coupon SIMPLEHACKS)
    ✅ If you want to be the first to be notified about the new tutorials then please subscribe to this channel. / @wpsimplehacks
    ✅ BEST WORDPRESS THEMES:
    Blocksy theme: wpsimplehacks.com/blocksy (SAVE 10% Coupon WPSH10)
    Kadence Theme: wpsimplehacks.com/kadence (SAVE 10% Coupon SIMPLEHACKS)
    Astra Theme: wpsimplehacks.com/astra
    GeneratePress: wpsimplehacks.com/generatepress
    OceanWP: wpsimplehacks.com/oceanwp (SAVE 10% Coupon WPSH10)
    ✅ AWESOME WORDPRESS PLUGINS:
    WPCodeBox wpsimplehacks.com/wpcodebox (SAVE 20% Coupon WPSH20)
    WooLentor Elementor/Gutenberg add-on wpsimplehacks.com/woolentor (SAVE 20% Coupon WPSH20)
    Best Wordpress Backup, Migration and Staging plugin - WpVivid Pro wpsimplehacks.com/wpvidid (SAVE 20% Coupon WPSH20)
    Best Gutenberg Blocks addon - Kadence Blocks wpsimplehacks.com/kadenceblocks (SAVE 10% Coupon SIMPLEHACKS)
    Best forms plugin - Fluent Forms: wpsimplehacks.com/fluentforms (SAVE 20% Coupon: WPSH20)
    WP Social Ninja wpsimplehacks.com/socialninja (SAVE 20% Coupon: WPSH20)
    Best for email marketing - Fluent CRM: wpsimplehacks.com/fluentcrm (SAVE 20% Coupon: WPSH20)
    Best for creating tables - Ninja Tables wpsimplehacks.com/ninjatables (SAVE 20% Coupon: WPSH20)
    Best events calendar and ticket selling plugin - WP Eventin wpsimplehacks.com/wp-eventin (SAVE 20% Coupon: WPSH20)
    Best Wordpress LMS - Tutor LMS wpsimplehacks.com/tutorlms (SAVE 20% Coupon thmwelcome20)
    Best Wordpress SEO plugin - SEOPress wpsimplehacks.com/seopress
    Image Map Pro - wpsimplehacks.com/imagemap
    ✅ AWESOME WOOOCOMMERCE EXTENSIONS:
    Best Woocommerce Swiss Knife tool - Kadence WooExtras wpsimplehacks.com/wooextras (SAVE 10% Coupon SIMPLEHACKS)
    Advanced Dynamic Pricing Pro wpsimplehacks.com/dynamic-pri... (SAVE 20% Coupon: WPSH20)
    Phone orders For Woocommerce Pro wpsimplehacks.com/phone-order... (SAVE 20% coupon: WPSH20)
    Advanced Orders Export Pro wpsimplehacks.com/export-orde... (SAVE 20% coupon: WPSH20)
    Best Woocommerce sidecart plugin - Woocommerce Cart in One wpsimplehacks.com/cartinone
    TIMESTAMPS
    00:00 Overview
    01:05 Install a Code Snippets plugin
    01:48 Add Woocommerce shipping class
    02:51 Hide Woocommerce shipping methods for specific shipping classes
    05:51 Display shipping class name in cart and checkout page
    06:55 Display message on cart and checkout page for specific shipping class
    07:56 How to find Woocommerce hooks?
    09:05 Final test
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 41

  • @dadadada-of8bj
    @dadadada-of8bj ปีที่แล้ว

    Thank you! It's the first time I try to use code snippets and I followed the lines and added a couple of the snippets, and they work like a magic.

  • @ingarnt
    @ingarnt 3 หลายเดือนก่อน

    Big thanks! Works like a charm for one of my two use-cases.
    However, I am not a PHP expert. I also need a slight variation on this. I need to hide a shipping method if there are no 'heavy' shipping-class products in the cart. Or the logic could be if there are ONLY 'light' shipping-class products in the cart, then hide Flat_rate:2, flat_rate:5 and flat_rate:7
    i.e.
    If no pallet items (shipping-class 'heavy') in cart, then remove Pallet shipping-method

    • @wpsimplehacks
      @wpsimplehacks  2 หลายเดือนก่อน +1

      See this heare below. Change "heavy" and "light" with your own shippin class slug here: if ($shipping_class == 'light')
      This codes removes specific shipping methods if cart contains products with either "heavy" or "light" shipping class. I cart contains both classes then "heavy" is prioritized.
      add_filter('woocommerce_package_rates', 'modify_shipping_rates_based_on_class', 10, 2);
      function modify_shipping_rates_based_on_class($rates, $package) {
      $has_light = false;
      $has_heavy = false;
      // Check each cart item for shipping classes. Change this value with your own shipping class slug. 'heavy'
      foreach ($package['contents'] as $item_id => $values) {
      $product = $values['data'];
      $shipping_class = $product->get_shipping_class();
      if ($shipping_class == 'light') {
      $has_light = true;
      }
      if ($shipping_class == 'heavy') {
      $has_heavy = true;
      }
      }
      // Apply rules based on shipping class presence
      if ($has_heavy) {
      // Unset rates for "heavy"
      unset($rates['flat_rate:1']);
      unset($rates['flat_rate:6']);
      unset($rates['flat_rate:22']);
      } else if ($has_light) {
      // Unset rates for "light"
      unset($rates['local_pickup:21']);
      unset($rates['flat_rate:16']);
      unset($rates['flat_rate:6']);
      unset($rates['flat_rate:25']);
      }
      return $rates;
      }

  • @jeremylhomme7581
    @jeremylhomme7581 2 ปีที่แล้ว

    Big thanks to you man!! It works like a charm

  • @161633232
    @161633232 ปีที่แล้ว

    Excellent tutorial! Thanks a lot. It worked fine for me :)

  • @UlkamediaUK
    @UlkamediaUK 9 วันที่ผ่านมา

    Thanks, working well to disable the Free Shipping option at cart but unfortunately isn't displaying the associated price from the defined shipping class. Instead it's showing the "No shipping options were found" message when free shipping is still an active shipping method in shipping zones options. How can we fix that please?

  • @timbrazeal4751
    @timbrazeal4751 2 ปีที่แล้ว

    You're brilliant

  • @Pororos
    @Pororos ปีที่แล้ว

    Thank you! Anything similar to notify a customer they have an "exclusive product" which can only be paid using a defined payment server, so they must pay it as is or remove the product to allow all the payment methods?

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      Sorry, can’t help you with that.

  • @SoftExpert1
    @SoftExpert1 2 ปีที่แล้ว

    Hi, I am delivering products to a specific area "Victoria Australia'. I want to have the shipping and calculation but also want to hide the 'ship to another address' checkbox along with its fields.

    • @wpsimplehacks
      @wpsimplehacks  2 ปีที่แล้ว

      Sorry, can’t help with that because this is tough one and needs some custom coding.

  • @datboyfemi
    @datboyfemi 2 ปีที่แล้ว

    Greetings from Nigeria

    • @wpsimplehacks
      @wpsimplehacks  2 ปีที่แล้ว

      Greetings from Estonia ☺️

  • @lissettetalhouk4436
    @lissettetalhouk4436 10 หลายเดือนก่อน

    Hello!!!!! Thanks for the video, how can I delete only the shipping methods at checkout? and only that it appears in the cart, thank you, I just need the shipment to appear in the checkout that was selected by the customer in the shopping cart, thank you

    • @wpsimplehacks
      @wpsimplehacks  10 หลายเดือนก่อน

      Sorry, can’t help you with that.

  • @RohitChourasia
    @RohitChourasia 2 ปีที่แล้ว

    Hi, Great video. Your code also works like a charm! However I have 12 shipping zones which have 12 shipping methods (with different slugs) to be hidden for just 1 Shipping Class. So do I have to paste this code 12 times under each other? OR do I have to create 12 different snippets altogether? Hope you can help me on this.

    • @wpsimplehacks
      @wpsimplehacks  2 ปีที่แล้ว +1

      See this snippet here wpsimplehacks.com/how-to-hide-woocommerce-shipping-methods/#how-to-hide-multiple-woocommerce-shipping-methods-for-specific-shipping-classes
      This snippet helps you to hide multiple shipping methods that are using same shipping class.

  • @Jabro111
    @Jabro111 2 ปีที่แล้ว

    Thank You 😉I's works, but but only to hide method for one shipping class :/ how to change the code to hide one shipping method for multiple classes? For example - shipping methos 1 works only for 1kg un 3 kg shipping class, but doesn't works for 5kg, 10kg and 20kg shipping classes? Please help :)

    • @wpsimplehacks
      @wpsimplehacks  2 ปีที่แล้ว

      Maybe this one here helps you out wpsimplehacks.com/how-to-hide-woocommerce-shipping-methods/#how-to-hide-multiple-woocommerce-shipping-methods-for-specific-shipping-classes

  • @qariasim
    @qariasim ปีที่แล้ว

    you're brilliant 😊it worked perfectly for two classes, one with "Free Shipping only" and the other one with either "Flat rate" or "Cash on delivery". But when two items from different classes are added to cart, it says: No shipping options were found for. I've tried all codes with no luck. Please help!

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      Probably it means that one product deactivates flat rate, another one cash on delivery. Since these two products are added to the cart your checkout doesn’t have any shipping options. If you delete one of these from the cart then one shipping method will be available.

    • @qariasim
      @qariasim ปีที่แล้ว

      @@wpsimplehacks Thanks a lot for the reply. Would you plz advise how to tweak the code to show the applicable shipping method(s) based on the products added to cart, i.e. if all products has free shipping then hide all other methods, and if one item added with the other two methods then show other methods and hide free shipping. 🙏

  • @mohammadal-najjar5115
    @mohammadal-najjar5115 2 ปีที่แล้ว

    Hi is there any update in woocommerce that made this snipt of code is not working because I tried so much but it did not work

    • @wpsimplehacks
      @wpsimplehacks  2 ปีที่แล้ว +1

      I just tested and it worked like it did before, that is - without any issues.

  • @I-rshad
    @I-rshad ปีที่แล้ว

    Sir can you help me with the code for showing paid shipping option when both the free shipping and paid shipping items comes for checkout.
    1-hide free shipping for shipping class with 20$ shipping cost
    2-hide this $20 shipping class option for the free shipping items
    Now when both of the thing comes sametime in cart showing no shipping options available

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      Sorry, can’t help you with that.

  • @banatcollections527
    @banatcollections527 7 หลายเดือนก่อน

    how to remove shipping address down of delivery charge in cart page.

    • @wpsimplehacks
      @wpsimplehacks  7 หลายเดือนก่อน

      Woocommerce settings >> Shipping

  • @oceanwired
    @oceanwired 11 หลายเดือนก่อน

    How to disable checkout or "add to cart" by shipping class?

    • @wpsimplehacks
      @wpsimplehacks  11 หลายเดือนก่อน

      What do you mean by that? :)

  • @TheyCallMeRome
    @TheyCallMeRome ปีที่แล้ว

    great tutorial, but when you don't have the class in the cart, example local courier-only, then its still showing the courier-only method

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      Hence the video "How to hide shipping methods with shipping classes" :) If there’s no class added, then you can’t hide it with this method :)

    • @TheyCallMeRome
      @TheyCallMeRome ปีที่แล้ว

      @@wpsimplehacks
      Do you have a video for that? right now the courier-only is showing though there is no product with that class

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      All my shipping related hacks are in this video: th-cam.com/video/lQs48LV5rbA/w-d-xo.html

  • @dsuinfotech
    @dsuinfotech ปีที่แล้ว

    Hello how I can achieve below requirement?
    I want to sell my product in all countries with weight based shipping cost.
    If buyer from US shipping cost will be apply as upto 250gm weight $50 and there after if user add any weight product in cart charges will be apply as $10 1-250gm &
    Means for 350gm charges will be $60
    For 550gm $70
    Your help will be aplricated. Thank you

    • @wpsimplehacks
      @wpsimplehacks  ปีที่แล้ว

      Sorry, can't help you with that

    • @dsuinfotech
      @dsuinfotech ปีที่แล้ว

      @@wpsimplehacks Thanks for reply