Skip to content

Instantly share code, notes, and snippets.

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 PluginHive/50f2e4a8ee142864dfab2a93368b6813 to your computer and use it in GitHub Desktop.
Save PluginHive/50f2e4a8ee142864dfab2a93368b6813 to your computer and use it in GitHub Desktop.
Code snippet to hide non-UPS shipping services if a customer selects an Access Point at Checkout. Work with PluginHive WooCommerce UPS Shipping Plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_if_accesspoint', 10, 2);
function wf_hide_shipping_method_if_accesspoint( $available_shipping_methods, $package ){
global $woocommerce;
$shipping_accesspoint = WC()->customer->__get('shipping_accesspoint');
if( !empty($shipping_accesspoint) ){
$decoded_accesspoint = json_decode($shipping_accesspoint);
if(isset($decoded_accesspoint->AddressKeyFormat)){
if( !empty( $decoded_accesspoint->AddressKeyFormat->AddressLine ) ){
foreach ($available_shipping_methods as $shipping_method => $value) {
if( strpos( $shipping_method, 'wf_shipping_ups' ) == false ) {
unset($available_shipping_methods[$shipping_method]);
}
}
}
}
}
return $available_shipping_methods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment