Skip to content

Instantly share code, notes, and snippets.

@Nishadup
Created September 25, 2018 13:43
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 Nishadup/2ae0b0a57fac406abcabef8556645de3 to your computer and use it in GitHub Desktop.
Save Nishadup/2ae0b0a57fac406abcabef8556645de3 to your computer and use it in GitHub Desktop.
Snippet to auto choose the shipping method on creating the UPS label, even the order is placed non-ups services. Work with pluginhive UPS shipping https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
add_filter('ph_ups_label_shipping_method', 'ph_ups_label_shipping_method', 10, 2);
function ph_ups_label_shipping_method( $shippingmethod, $order ){
//Config this array
$shipping_method_map = array(
'free_shipping' => '03',
'flat_rate' => '12',
);
$shipping_method = @array_shift($order->get_shipping_methods());
$shipping_method_id = $shipping_method['method_id'];
return isset( $shipping_method_map[$shipping_method_id] ) ? $shipping_method_map[$shipping_method_id] : $shippingmethod;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment