Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 19, 2019 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/f6c84df50af11b5f952e170379933f7f to your computer and use it in GitHub Desktop.
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/
/**
* 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