DHL Express Useful Filters (Snippets) for wordpress/woocommerce

shipidhlexpresssnippets

This document explains the available filters/hooks provided by the DHL Express WooCommerce plugin, along with their purpose, parameters, and example use cases.


1. Restrict Rates for a Specific Country

Hook: a2z_dhlexpress_rate_packages

  • Parameters:

    • $package (array): Shipping package data.
  • Purpose: Excludes DHL rates for specific destination countries.

  • Example: Block all shipments to Russia (RU).

add_filter("a2z_dhlexpress_rate_packages","a2z_dhlexpress_rate_packages_func",10,1);
function a2z_dhlexpress_rate_packages_func($package){
    $return_package = array();
    if($package['destination']['country'] == 'RU'){
        return $return_package;
    }
    return $package;
}

2. Flat Rate Based on Order Total

Hook: hitstacks_dhlexpress_rate_cost

  • Parameters:

    • $rate_cost (float): Default shipping cost.

    • $rate_code (string): DHL service code.

    • $order_total (float): Cart/order total.

  • Purpose: Defines a flat rate or free shipping when order total exceeds threshold.

  • Example: Free shipping above $250.

function hitstacks_dhlexpress_rate_cost_fnc($rate_cost, $rate_code, $order_total){
    if($order_total > 250){
        return 0;
    }
    return 20;
}
add_filter("hitstacks_dhlexpress_rate_cost", "hitstacks_dhlexpress_rate_cost_fnc", 10,3);

3. Change Estimated Delivery Date Format/Text

Hook: hitstacks_dhlexpres_delivery_date

  • Parameters:

    • $string (string): Default formatted text.

    • $est_date (string): Estimated delivery date.

    • $est_time (string): Estimated delivery time.

  • Purpose: Customize delivery estimate display on checkout.

add_filter('hitstacks_dhlexpres_delivery_date', 'hit_dhl_est_delivery_format',10,3);
function hit_dhl_est_delivery_format($string, $est_date, $est_time){
    return $string; // Replace with custom format
}

4. Sort Rates (Lowest to Highest)

Hook: woocommerce_package_rates

  • Parameters:

    • $rates (array): List of available shipping methods.

    • $package (array): Shipping package details.

  • Purpose: Reorder DHL rates at checkout.

add_filter( 'woocommerce_package_rates' , 'hitshipo_sort_shipping_methods', 10, 2 );
function hitshipo_sort_shipping_methods( $rates, $package ) {
    if ( empty( $rates ) || !is_array( $rates ) ) return;
    uasort( $rates, function ( $a, $b ) {
        if ( $a == $b ) return 0;
        return ( $a->cost < $b->cost ) ? -1 : 1;
    });
    return $rates;
}

5. Display Fixed Rate During Checkout

Hook: a2z_dhlexpress_manual_flat_rates

  • Parameters:

    • $package (array): Shipping package details.
  • Purpose: Replace DHL rates with static flat rates.

add_filter("a2z_dhlexpress_manual_flat_rates","a2z_dhlexpress_manual_flat_rates_func",10,1);
function a2z_dhlexpress_manual_flat_rates_func($package){
    return array(
        array("rate_code" => "I", "name" => "DHLExpress Domestic – I", "rate" => "10"),
        array("rate_code" => "N", "name" => "DHLExpress Domestic – N", "rate" => "20")
    );
}

6. Free Shipping Based on Product SKU

Hook: a2z_dhlexpress_rate_based_product

  • Parameters:

    • $products (array): Cart products considered for shipping.
  • Purpose: Grant free shipping if cart contains certain SKUs.

add_filter("a2z_dhlexpress_rate_based_product","a2z_dhlexpress_rate_based_product_fun",10,1);
function a2z_dhlexpress_rate_based_product_fun($products){
    $free_product = array('SHSJGAHGH','CFSL6813DB');
    foreach($products as $item_key => $val){
        $product = $val['data'];
        $product_data = $product->get_data();
        $exist = array_intersect(array($product_data['sku']),$free_product);
        if(!empty($exist)){
            unset($products[$item_key]);
        }
    }
    if(empty($products)){
        return 0;
    }
    return $products;
}

7. Customize Insurance Option

Hook: hitshipo_ins_ship

  • Parameters:

    • $insurance (string): Default insurance setting.

    • $vendor (string): Vendor name.

    • $order (array): Order details.

  • Purpose: Enable or disable insurance dynamically.

add_filter( 'hitshipo_ins_ship' , 'hitshipo_ins_ship_fun', 10, 3 );
function hitshipo_ins_ship_fun($insurance="no", $vendor="default", $order=[]){
    return "yes";
}

8. Customize Insurance Amount

Hook: hitshipo_ins_val_ship

  • Parameters:

    • $insurance_value (float): Default insurance amount.

    • $vendor (string): Vendor name.

    • $order (array): Order details.

  • Purpose: Modify insurance value for shipments.

add_filter( 'hitshipo_ins_val_ship' , 'hitshipo_ins_val_ship_fun', 10, 3 );
function hitshipo_ins_val_ship_fun($insurance_value=0, $vendor="default", $order=[]){
    return 10;
}

9. Disable Currency Conversion

Hook: hit_do_conversion_while_label_generation

  • Parameters:

    • $enabled (bool): Currency conversion status.

    • $toCounty (string): Destination country.

  • Purpose: Prevent currency conversion while generating DHL labels.

add_filter('hit_do_conversion_while_label_generation', 'hits_curr_con', 10, 2);
function hits_curr_con($enabled = true, $toCounty = ""){
    return false;
}

10. Modify Products for Shipment

Hook: hitshipo_prods_to_ship

  • Parameters:

    • $products (array): Products being shipped.
  • Purpose: Adjust product list before label creation.

add_filter('hitshipo_prods_to_ship', 'hits_product_modifier', 10, 1);
function hits_product_modifier($products = []){
    // custom modifications
    return $products;
}

11. Hide Invoice for Specific Countries

Hook: hits_show_invoice

  • Parameters:

    • $enabled (bool): Invoice visibility.

    • $toCounty (string): Destination country.

    • $type (string): Invoice type.

  • Purpose: Restrict invoice generation based on country.

add_filter('hits_show_invoice', 'hits_show_invoice_handle', 10, 3);
function hits_show_invoice_handle($enabled = true, $toCounty = "", $type=""){
    $disabled_countries = ["GB", "US", "DE"];
    if(!empty($toCounty) && in_array($toCounty, $disabled_countries)){
        $enabled = false;
    }
    return $enabled;
}

12. Set Receiver VAT

Hook: hitshipo_dhlexpress_receiver_vat

  • Parameters:

    • $rec_vat (string): Receiver VAT number.

    • $order (array): Order details.

  • Purpose: Dynamically assign VAT number for receiver.

add_filter( 'hitshipo_dhlexpress_receiver_vat' , 'hitshipo_dhl_receiver_vat_fun', 10, 2 );
function hitshipo_dhl_receiver_vat_fun($rec_vat="", $order=[]){
    $rec_vat = "qw12345";
    return $rec_vat;
}

13. Change Inbound Commodity Based on Receiver Country

Hook: a2z_dhlexpress_cc_inb

  • Parameters:

    • $saved_cc_inb (string): Default commodity code.

    • $product_id (int): WooCommerce product ID.

    • $to_country (string): Destination country.

  • Purpose: Modify commodity code depending on receiver’s country.

add_filter('a2z_dhlexpress_cc_inb', 'a2z_dhlexpress_cc_inb_fun', 10, 3);
function a2z_dhlexpress_cc_inb_fun($saved_cc_inb="", $product_id="", $to_country=""){
    $saved_cc_inb = "12345678";
    return $saved_cc_inb;
}

Conclusion

These filters provide powerful customization options for DHL Express WooCommerce integration. They allow developers to tailor shipping behavior, rates, insurance, invoicing, and compliance to business requirements.

If you need any new snippet or customization, we help you. contact support@myshipi.com or https://app.myshipi.com/support

Start with Our Free Plan

Shipping rates, store integration, and 50 order shipments - yours for a lifetime!

*No credit card required

Create Free Account