Please consider leaving a donation if you appreciate this information. Lightning network now available
WooCommerce Memberships offers some member perks out of the box and there are more perks that are being discussed here – one of which is free shipping for members. This has not been implemented yet, but it could be achieved via custom code. WooCommerce provides a filter named woocommerce_shipping_zone_shipping_methods which can be used to remove free shipping for non-members. Suppose you have a method with an id of free_shipping that only wants to be displayed to active members. The following code snippet would do just that
Not sure what to do with code snippets? See What Do I Do With These Code Snippets?
Please consider leaving a donation if you appreciate this information. Lightning network now available
monstermage says
What if I wanted to customize this snippet for a specific member?
Would it be like this?
add_filter( ‘woocommerce_shipping_zone_shipping_methods’, ‘custom_shipping_methods’ );
function custom_shipping_methods( $available_methods ) {
foreach ( $available_methods as $key => $method ) {
//don’t remove from admin & show free shipping for active members
//only for silver members
if ( function_exists( ‘wc_memberships_is_user_active_member( $user_id, ‘silver’ )’ ) && ! is_admin() && ‘free_shipping’ === $method->id && ! wc_memberships_is_user_active_member() ) {
unset( $available_methods[ $key ] );
}
}
return $available_methods;
}
monstermage says
In addition. When I implement the code exactly as you have it. Logged in as admin does not show free shipping. As a guess it does not show free shipping, though if you are logged in as a member it does show it. Though it shows both options, the flat rate shipping and the free shipping.