Skip to content

WooCommerce Shipping — General Hooks

These are standard WooCommerce hooks that can be used to modify shipping rates and behavior across any of our shipping method plugins. Replace {shipping_method_id} with the appropriate ID (e.g., gpost_courier, wolt, quickshipper).


woocommerce_package_rates

Type: filter When: When calculation of shipping rates for a package is done.

Use this filter to conditionally modify shipping rates, change labels, or remove certain methods based on cart contents, customer location, or other criteria.

ParamTypeDescription
$ratesarrayArray of WC_Shipping_Rate objects
$packagearrayThe shipping package details

Example: Free shipping if cart total > 100

add_filter(
    'woocommerce_package_rates',
    function( $rates ) {
        $shipping_id = '{shipping_method_id}';
        if ( isset( $rates[ $shipping_id ] ) ) {
            $total = WC()->cart->get_cart_contents_total();

            if ( $total >= 100.00 ) {
                $rates[ $shipping_id ]->label = __( 'Free Shipping', 'your-text-domain' );
                $rates[ $shipping_id ]->cost  = 0;
            }
        }

        return $rates;
    },
    100
);

Example: Free shipping for specific city

add_filter(
    'woocommerce_package_rates',
    function( $rates ) {
        $shipping_id = '{shipping_method_id}';
        if ( isset( $rates[ $shipping_id ] ) ) {
            $city = WC()->customer->get_shipping_city();

            // '1' is often an ID used in Georgian Post for Tbilisi, but check your specific lookup.
            if ( '1' === $city ) {
                $rates[ $shipping_id ]->label = __( 'Free Delivery', 'your-text-domain' );
                $rates[ $shipping_id ]->cost  = 0;
            }
        }

        return $rates;
    },
    100
);

Example: Free shipping if cart contains specific product

add_filter(
    'woocommerce_package_rates',
    function( $rates ) {
        $shipping_id = '{shipping_method_id}';
        if ( isset( $rates[ $shipping_id ] ) ) {
            $free_shipping_product_id = 30; // Change to your product ID
            $cart_items  = WC()->cart->get_cart();
            $product_ids = [];

            foreach ( $cart_items as $item ) {
                $product_ids[] = $item['product_id'];
            }

            if ( in_array( $free_shipping_product_id, $product_ids, true ) ) {
                $rates[ $shipping_id ]->label = __( 'Free', 'your-text-domain' );
                $rates[ $shipping_id ]->cost  = 0;
            }
        }

        return $rates;
    },
    100
);

Example: Free shipping by cart item count

add_filter(
    'woocommerce_package_rates',
    function( $rates ) {
        $shipping_id = '{shipping_method_id}';
        if ( isset( $rates[ $shipping_id ] ) ) {
            $count = WC()->cart->get_cart_contents_count();

            if ( $count > 1 ) {
                $rates[ $shipping_id ]->label = __( 'Free Delivery', 'your-text-domain' );
                $rates[ $shipping_id ]->cost  = 0;
            }
        }

        return $rates;
    },
    100
);