Last active
January 11, 2021 16:46
-
-
Save jessepearson/c0c62c5e0f3e776da99fa70901184256 to your computer and use it in GitHub Desktop.
Revisions
-
jessepearson renamed this gist
Jan 11, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jessepearson created this gist
Jan 11, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <?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; }