skip to Main Content

I want change the shipping method title (view image) after create the order. I using hook "woocommerce_thankyou", but i can’t change the title of existing shipping.

image with i want change

I find this code, but with this code add a new shipping method but it’s not what i want, because after this code i have 2 shipping method.

$item = new WC_Order_Item_Shipping();
$item->set_method_title( "SEUR Estándar" );
$item->set_method_id( "seur" ); // set an existing Shipping method rate ID
//$item->set_total( $new_ship_price ); // (optional)
//$item->calculate_taxes($calculate_tax_for);

$order->add_item( $item );

$order->save();

Thanks for your help.

2

Answers


  1. Chosen as BEST ANSWER

    I find this solucion and thanks for all Jo Kolov

    foreach($rates as $rate_id => $rate) { 
        if ( 'seur' === $rate->method_id ) {
            $rates[$rate_id]->label = __( 'SEUR Estándar', 'woocommerce' );
        }
    }
    

  2. If I understand correctly, you want to change the shipping method TITLE only in admin area ?

    For example :
    => In WC settings, shipping method title = SEUR Estándar (this title is displayed to customers during checkout and on emails)
    => In WC admin, when you handle the order, you want SEUR Estándar is changed to SEUR

    For this, you can try something like that (not tested), hooking only the displayed title

    add_filter( 'woocommerce_shipping_method_title', function( $method_title, $method_id ) {
        if ( ! is_admin() || ! 'shop_order' === get_post_type() ) { // change applied only on admin order page
            return $method_title;
        }
        if ( $method_id == 'seur' ) { // change condition to match what you need
            $method_title = 'SEUR'; // new method title
        }
        return $method_title;
    }, 10, 2 );
    

    If you want to change the shipping method title in other areas, think about what it is easier and need less job : change only for customer in front end, change only for admin, change in emails… ? Then adapt conditions in above snippet.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search