Home / Admin / Change Method Label
Duplicate Snippet

Embed Snippet on Your Site

Change Method Label

Code Preview
php
<?php
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wcv_override_vendor_shipping_label', 10, 2 ); 
function wcv_override_vendor_shipping_label( $label, $method ){
	$label = 'Flat-rate'; // <- Change this to your preferred prefix 
	$has_cost  = 0 < $method->cost;
	$hide_cost = ! $has_cost && in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true );
	if ( $has_cost && ! $hide_cost ) {
		if ( WC()->cart->display_prices_including_tax() ) {
			$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
			if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
				$label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
			}
		} else {
			$label .= ': ' . wc_price( $method->cost );
			if ( $method->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
				$label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
			}
		}
	}
	return $label;
}

Comments

Add a Comment