Created
September 14, 2018 07:45
-
-
Save varun-pluginhive/14fd167b4fb127a6a4b8af2513fc4fae to your computer and use it in GitHub Desktop.
Snippet to map WooCommerce Shipping Method name to another name (Shipping Meta). PluginHive Plugins -https://www.pluginhive.com/
This file contains 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 characters
/** | |
* Snippet to map woocommerce shipping method name to another name. | |
* Created at : 14 Sep 2018 | |
* Updated at : 14 Sep 2018 | |
* PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
* Gist Link : https://gist.github.com/varun-pluginhive/14fd167b4fb127a6a4b8af2513fc4fae | |
*/ | |
if( ! function_exists('ph_map_wc_shipping_method_name') ) { | |
function ph_map_wc_shipping_method_name( $shipping_rates ) { | |
$shipping_method_name_map_arr = array( | |
'Flat rate 1' => 'FedEx', // Shipping Name in Cart => Name to be displayed in order page with Shipping | |
'Free shipping' => 'UPS', | |
); | |
$meta_name_to_set = 'Shipping Company'; // Title for your mapped name | |
foreach( $shipping_rates as &$shipping_rate ) { | |
$rate_title = $shipping_rate->get_label(); | |
if( ! empty($shipping_method_name_map_arr[$rate_title]) ) { | |
$shipping_rate->add_meta_data( $meta_name_to_set, $shipping_method_name_map_arr[$rate_title] ); | |
} | |
} | |
return $shipping_rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'ph_map_wc_shipping_method_name' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment