Last active
September 19, 2019 06:47
-
-
Save xadapter/f6c84df50af11b5f952e170379933f7f to your computer and use it in GitHub Desktop.
Snippet to change weight in Woocommerce Canada Post Rate Request. WooCommerce Canada Post Shipping Plugin with Print Label - https://www.pluginhive.com/product/woocommerce-canada-post-shipping-plugin-with-print-label/
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 change weight in Woocommerce Canada Post Rate Request. | |
* Created at : 10 Aug 2018 | |
* Updated at : 10 Aug 2018 | |
* PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
* Gist Link : https://gist.github.com/xadapter/f6c84df50af11b5f952e170379933f7f | |
*/ | |
add_filter( 'xa_canadapost_rate_request', function( $request ){ | |
$default_weight = 15; // In kg | |
$request_arr = explode( '<weight>', $request ); | |
if( ! empty($request_arr[1]) ) { | |
$new_request = $request_arr[0].'<weight>'. $default_weight. '</weight>' ; | |
$request_arr = explode( '</weight>', $request_arr[1] ); | |
if( ! empty($request_arr[1]) ) { | |
$request = $new_request.$request_arr[1]; | |
} | |
} | |
return $request; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment