Hiding/disabling a shipping service

Code Snippet 01 : Hide a shipping method for a particular Shipping Class in USPS Plugin
With the below given piece of code, you can hide an unwanted shipping method(service) for the product(in cart) of the particular shipping class.
Steps to add Code Snippet
  1. Add the following code to your functions.php or any where relevant.
  2. You need to Products > Shipping Class in Admin Panel.
  3. You also need to get the code for the service.
With this, if any product(in cart) belongs to_hide array will not be available in cart/checkout page.
The Code is as given below:

Code Snippet 02 – Hide the undesired service for the required states

With this piece of code, you can hide an undesired service for the required states even though the service is enabled in FedEx plugin Settings.
Steps to add Code Snippet
    1. Add the following code to your functions.php or any where relevant.
    2. Find the SERVICE_CODE from the FedEx shipping settings page and prepare the shipping service “wf_fedex_woocommerce_shipping:SERVICE_CODE”.
    3. Modify the shipping service and the list of states in the following code as per your requirement.
      For example: To disable FedEx ground shipping service for the couple of states in USA. $exclude = array( ‘wf_fedex_woocommerce_shipping:FEDEX_GROUND’ => array(‘AK’,’AZ’,’CA’,’CO’));

The Code is as given below:

Code Snippet 03 – Hide the undesired service for the required Zip Codes(FedEx)

With this piece of code, you can hide an undesired service for the required Zip Codes even though the service is enabled in FedEx plugin Settings.

Steps to add Code Snippet

  1. Add the following code to your functions.php or any where relevant.
  2. You need to get the code for the service.
  3. Unset the rates for  required service code.
    For example: To disable FedEx ground shipping service for the zip code 93999, the code is unset( $rates [‘wf_fedex_woocommerce_shipping:FEDEX_GROUND’] );

The Code is as given below:

Code Snippet 04 – Hide a shipping method for the particular product(s)
With the given piece of code, you can hide an unwanted shipping method for the particular product(s) which is in the cart.
Add the following code to your functions.php or any where relevant.

Code Snippet 05 – Hide the undesired method for the particular existing shipping class(Australia Post)

With this piece of code, you can hide an undesired service for the required existing shipping class.

Steps to add Code Snippet

  1. Add the following code to your functions.php or any where relevant.
  2. You need to get the code for the service.
  3. Australia Post methods will not be shown in the cart/checkout page, if the product belongs to the $shipping_class_ids array.

The Code is as given below:

Code Snippet 06 – Hide the undesired First Class Mail services on WooForce USPS Plugin. 

IDs returned by USPS API for the First-Class Mail services such as First-Class Mail Postcards, First-Class Mail Large Envelope, First-Class Mail Stamped Letter and First-Class Mail Parcel are same. WooForce USPS plugin displays the lowest rate among these First- Class Mail services. If that to your needs, you can disable the undesired First-Class Mail services.
With this piece of code, you can hide undesired First-Class Mail services and display only required First-Class Mail Service.
For Example: In the below code, First-Class Mail services such as First-Class Mail Postcards, First-Class Mail Large Envelope and First-Class Mail Stamped Letter are disabled. The rate of only First-Class Mail Parcel will be displayed tomer.

Add the following code to your functions.php or any where relevant.The Code is as given below:

Code Snippet 07 – Hide/show USPS services based on the quantity of items in the cart

With this piece of code, you can hide/show a required USPS service based on quantity of items for the following cases:
  1. Showing only First Class Mail service if the cart contains  upto 2 items.
  2. Showing only  Standard Post (previously known as USPS Retail Ground) service if the cart contains more than 2 to 30 items.
  3. Not showing any USPS service if the cart contains more than 30 items.

Add the following code to your functions.php or any where relevant.The Code is as given below:

In the above code, $available_shipping_methods array stores all the information about the shipment package.  If $unit is less than 3, then only D_FIRST_CLASS shipping service is returned. If $unit is more than 2 and less than 31, then only D_STANDARD_POST shipping service is returned. If $unit is more than 30,then $available_shipping_methods is unset so that no USPS service will be displayed.

Scroll to Top