Created
September 25, 2018 13:43
-
-
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/
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
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