You can use this filter to determine if you are inside Vipps Checkout:
apply_filters('woo_vipps_is_vipps_checkout', false)
To filter away any methods/rates you don’t want in there, you can either use a filter on ‘woocommerce_package_rates’ which takes a list of WC_Shipping_Rate objects where you can check for instance the method_id of the rate, or you can directly add filters to
"woocommerce_shipping_{$shipping_method_id}_is_available"
— family of filters. Just return false if the above value is false.
Hi,
Thank you for a quick reply. I was testing this code below and this code only removes the local pickup shipping method from WooCommerce default checkout and not from the Vipps Checkout. Is there any other filter/action I could use that Vipps Checkout uses to fetch the shipping methods?
function filter_local_pickup_shipping_method( $rates, $package ) {
if ( is_user_logged_in() && get_user_meta( get_current_user_id(), 'b2b_user', true ) === 'true' ) {
foreach ( $rates as $rate_id => $rate ) {
if ( 'local_pickup' === $rate->method_id ) {
unset( $rates[ $rate_id ] );
break;
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'filter_local_pickup_shipping_method', 10, 2 );
When calculating shipping methods for Vipps Checkout, except if using static shipping, the user will never be “logged in” as such, since the callback is actually coming from Vipps, and not from the user. If you need to check the users’ capabilites, you would probably need to retrieve the user by email from the user database.
You should be able to remove the rate for Vipps Checkout specifically by doing
$is_checkout = apply_filters(('woo_vipps_is_vipps_checkout', false);
and modifying your filter to check for “$is_checkout || ...
“.
As mentioned you can also do something like (untested!):
add_filter('woocommerce_shipping_local_pickup_is_available', function ($ok) {
if (apply_filters('woo_vipps_is_vipps_checkout', false)) return false;
return $ok;
});
Thank you very much for excellent feedback. Do you know the ID for Porterbuddy and Posten?
I tried the following code but Porterbuddy and Posten cannot be removed.
add_filter('woocommerce_shipping_vipps_checkout_porterbuddy_is_available', function ($ok) {
if (apply_filters('woo_vipps_is_vipps_checkout', false)){
return false;
}
return $ok;
});
add_filter('woocommerce_shipping_porter_buddy_is_available', function ($ok) {
if (apply_filters('woo_vipps_is_vipps_checkout', false)){
return false;
}
return $ok;
});
Not sure 100% I understand, but for the Vipps Checkout specific methods there is another filter available also:
apply_filters('vipps_checkout_shipping_available', $ok, $shipping_method, $package);
Ignoring $package
you can test the value of $shipping_method->id
which will be vipps_checkout_porterbuddy and vipps_checkout_posten.
The basic filters 'woocommerce_shipping_vipps_checkout_porterbuddy_is_available'
and 'woocommerce_shipping_vipps_checkout_posten_is_available'
should work too.
Thank you for the answers. That worked perfectly.