You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WooCommerce 3中修改USPS配送方式的显示名称

Modify USPS Shipping Method Names in WooCommerce

Got it! To rename those USPS shipping options to shorter, cleaner labels, you can use WooCommerce's woocommerce_shipping_method_title filter hook. This lets you override the default title displayed in the cart and checkout pages.

Here's the code you'll need:

add_filter( 'woocommerce_shipping_method_title', 'custom_rename_usps_shipping_methods', 10, 2 );
function custom_rename_usps_shipping_methods( $original_title, $shipping_method ) {
    // Check the original title (matches what you see in cart/checkout)
    $lowercase_title = strtolower( $original_title );
    
    if ( $lowercase_title === 'first-class package service' ) {
        return 'Standard';
    } elseif ( $lowercase_title === 'priority mail' ) {
        return 'Priority';
    }
    
    // Return original title for all other shipping methods
    return $original_title;
}

How to use this code:

  • Add this snippet to your child theme's functions.php file. Always use a child theme so your changes don't get overwritten when you update your main theme.
  • If you don't want to edit theme files, use a custom code plugin to add the code safely.

Alternative (more reliable if titles change):

If you want to target the USPS methods by their internal IDs (which don't change even if the title updates), you can adjust the code to check the method's ID instead. For USPS, the IDs are typically something like usps_first_class and usps_priority_mail (your exact IDs might vary—you can find them by inspecting the shipping method settings in WooCommerce). Here's that version:

add_filter( 'woocommerce_shipping_method_title', 'custom_rename_usps_shipping_methods_by_id', 10, 2 );
function custom_rename_usps_shipping_methods_by_id( $original_title, $shipping_method ) {
    // Check the shipping method's internal ID
    switch( $shipping_method->id ) {
        case 'usps_first_class': // Replace with your actual First-Class ID
            return 'Standard';
        case 'usps_priority_mail': // Replace with your actual Priority Mail ID
            return 'Priority';
        default:
            return $original_title;
    }
}

Just replace the placeholder IDs with the ones from your WooCommerce USPS settings, and this will work even if the default titles get updated. Either way, once you add the code, the shipping labels should update immediately in your cart and checkout pages.

内容的提问来源于stack exchange,提问作者Austin Sobotka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:35:21