Skip to content

Instantly share code, notes, and snippets.

@xadapter

xadapter/functions.php

Last active Sep 19, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.