wedevtrust Logo

Mastering WooCommerce Shipping Classes: Your Guide to Effective eCommerce Shipping

WooCommerce Shipping
Image | CC0 pixabay
In this blog post, we dive deep into the world of WooCommerce, unveiling the secrets to seamlessly managing special shipping classes. These specialized classes empower you to apply distinct shipping rules to specific product categories, enhancing the transparency and convenience of your customers' shopping experience.

In the competitive landscape of eCommerce, WooCommerce stands as a powerful ally for online store owners. Yet, one challenge that frequently arises is the need to efficiently manage products with unique shipping requirements. Whether you deal in fragile goods, perishable items, or oversized merchandise, the ability to tailor shipping processes to specific product categories and regions of the world is paramount.

Special Rules for Special Features

In the world of eCommerce, dropshipping and calculating shipping costs for foreign countries can be challenging due to several key factors:

  1. Logistics and Suppliers: Dropshipping relies on third-party suppliers who may be located in different countries. Coordinating inventory levels, order fulfillment, and shipping logistics across international borders can be complex and prone to delays.

  2. Shipping Rates and Variability: Shipping costs for foreign countries vary widely depending on factors such as distance, shipping method, package size, and weight. Accurately estimating these costs for each product and destination can be a daunting task.

  3. Customs and Duties: Cross-border shipments often involve customs clearance and import duties. Navigating the legal and regulatory requirements of multiple countries adds another layer of complexity to the process.

  4. Currency Conversion: Dealing with different currencies when pricing products and calculating shipping costs can be confusing. Exchange rates can fluctuate, impacting your profit margins.

  5. Customer Expectations: International customers have varying expectations regarding shipping times and costs. Meeting these expectations while keeping shipping affordable can be challenging.

  6. Returns and Customer Service: Handling returns and providing customer support across time zones and languages can strain resources and require careful management.

In summary, dropshipping and calculating shipping costs for foreign countries involve intricate logistics, pricing challenges, and regulatory complexities. Success in this endeavor requires careful planning, reliable partners, and a solid understanding of the international eCommerce landscape.

This is why we show you how to restrict shipping for dropshipping-products to only one country in this blog post.

Structural Preparations

At first, we need to prepare WooCommerc to be able to handle this requirement.

Defining a Shipping Class

We need to define a shipping class at WooCommerce > Settings > Shipping > Shipping classes that resembles the products to restrict. We want to restrict all dropshipping products to only be shipped to Germany so let’s call it “Dropshipping”.

WooCommerce Shipping Class

Selecting Products

We then need to change the shipping class for our products at Products > Edit product > Shipping > Shipping class to “Dropshipping”.

Product Shipping Class

Features Needed

We need two seperate parts to make this work for our online shop:

  1. A notice displayed for the product: we want to indicate clearly that a specific produt is only send to one shipping zone.

  2. Restricion in cart: we need to display an error message as soon as a shipping class & zone combination is present in cart. In this case all shipping options will be deactivated.

Explaining the Code

First Function wdt_extend_availability

  • The function is named wdt_extend_availability and it accepts two parameters: $availability and $product.
  • $availability: This is the current availability text of the product.
  • $product: This represents the WooCommerce product object.

Inside the function

  • A variable $target_shipping_class is set to the string ‘dropshipping’.
  • An if condition checks if the shipping class of the product ($product->get_shipping_class()) matches the $target_shipping_class.
  • If the condition is true, a notice (<p class=”shipping-class-notice”>Diesen Artikel versenden wir <b>nur innerhalb Deutschlands</b>.</p>) is appended to the $availability text. This notice informs the customer that the item is only shipped within Germany.
  • Finally, the modified $availability is returned.
  • The add_filter function is a way to hook or insert the custom function into a specific action or filter provided by WordPress or plugins.
  • The filter hook here is woocommerce_get_availability_text, which allows you to modify the availability text in WooCommerce.
  • ‘wdt_extend_availability’ is the name of the function that will be called when the hook is executed.
  • 10 is the priority (default is 10), determining the order in which functions hooked to this action are executed.
  • 2 is the number of accepted parameters. In this case, it’s 2, which matches the two parameters $availability and $product in the wdt_extend_availability function.


In summary, the first function of the snippet checks if a product belongs to the “dropshipping” shipping class and, if so, appends a notice to its availability text indicating that the product is only shipped within Germany.

Second Function wdt_restrict_shipping

The function wdt_restrict_shipping aims to restrict certain products labeled as “dropshipping” via shipping class from being shipped outside a specific shipping zone (in this case, zone 1, which represents Germany.

Here’s a step-by-step breakdown:

  1. The function checks products in the customer’s cart.
  2. If a product is classified as “dropshipping”:
    1. It verifies if the shipping zone for the customer’s location is different from the allowed zone (zone 1, Germany).
    2. If it’s different, the function displays an error message saying the product is only shipped within Germany.
    3. It then removes all available shipping methods for the order.

In simpler terms: If a customer tries to order a “dropshipping” product and and their shipping zone is not the allowed one (Germany), they’ll see an error message, and no shipping options will be provided for the entire order.


The provided code snippet serves a critical function related to shipping logistics and business policies.

Targeted Shipping Restrictions: Some products might have specific shipping restrictions due to various reasons like legal regulations, shipping costs, or supplier agreements. The snippet ensures that products labeled as “dropshipping” are only shipped to a specified zone, likely representing a region or country.

Customer Experience: By providing clear notifications when a product can’t be shipped to a specific location, customers are informed upfront, avoiding potential misunderstandings or frustrations later in the checkout process.

Operational Efficiency: Implementing such restrictions programmatically ensures that the business doesn’t accidentally accept orders that they can’t fulfill due to shipping constraints. This helps in reducing operational hiccups, potential refunds, and customer service inquiries.

Flexibility: The code is designed in a way that allows easy modifications. If the business decides to change the restricted shipping class or the allowed zone, it can be done with minimal changes to the code.

Consistency: By programmatically enforcing these rules, the business ensures consistency. Every order will undergo the same checks, reducing the risk of human error.

You could as well achive this with a paid plugin like WooCommerce Conditional Shipping and Payments but it often makes sense for growing online businesses to implement focused solutions for the sake of perfomance.


Related Posts

Time to Update

Maintenance of High Turnover WooCommerce Stores

What to do when plugin updates suddenly cause problems for a high-traffic online store? We were faced with this task when a maintenance interval looked promising at first, but then led to inaccessibility of our client’s high-volume WooCommerce store under load.