skip to Main Content
IMPORTANT
There is currently an unexpected delay in support response time due to a personal emergency.
I greatly apologize for the inconvenience and will respond to each ticket as soon as possible.

Change Shipping Package Title

As of WooCommerce 2.6, the package titles are now able to be something more than Shipping #1, Shipping #2, etc… Using a filter, one can change the titles to something more helpful. For example, if you separate your cart into packages based on individual shipping classes, you could title the package after the class itself. The example code below will do just that:

function wc_change_pkg_titles( $current_title, $pkg_id, $package ) {

    // exit if package error
    if( ! isset( $package['contents'] ) || ! is_array( $package['contents'] ) ) return $current_title;

    foreach( $package['contents'] as $key => $item ) {
        $product = $item['data'];
        $shipping_class_id = $product->get_shipping_class_id();
        $shipping_class = get_term( $shipping_class_id );
    }

    return ( $shipping_class ) ? $shipping_class->name : $current_title;
        
}
add_filter( 'woocommerce_shipping_package_name', 'wc_change_pkg_titles', 10, 3 );

  • Was this article helpful ?
  • yesno
1 out of 1 visitors found this article helpful
Views: 320
Back To Top