Created
July 14, 2020 06:10
-
-
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/
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('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