Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active January 11, 2021 16:46
Show Gist options
  • Save jessepearson/c0c62c5e0f3e776da99fa70901184256 to your computer and use it in GitHub Desktop.
Save jessepearson/c0c62c5e0f3e776da99fa70901184256 to your computer and use it in GitHub Desktop.
Allows to change up the name of the Distance Rate label for WooCommerce Distance Rate Shipping.
<?php // do not copy this line
/**
* Allows to change up the name of the Distance Rate label for WooCommerce Distance Rate Shipping.
*/
add_filter( 'woocommerce_shipping_method_add_rate_args', 'jp_woocommerce_shipping_method_add_rate_args_2021_01_11', 50, 2 );
function jp_woocommerce_shipping_method_add_rate_args_2021_01_11( $args, $package ) {
// Check to see if it's a distance rate method.
if ( false !== strpos( $args['id'], 'distance_rate' ) ) {
// Get just the time and distance between the parenthesis.
preg_match('/\(.*\)$/', $args['label'], $matches );
$args['label'] = $matches[0]; // Contains only distance and time like (10.2 mi; 19 mins)
// Now we change mi to baby steps, and mins to years.
// Need to make sure to keep the ; and ) in the search and replace in order to not replace the wrong thing.
$args['label'] = str_replace( 'mi;', 'baby steps;', $args['label'] );
$args['label'] = str_replace( 'mins)', 'years)', $args['label'] );
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment