martini0 Posted August 5, 2022 Author Share Posted August 5, 2022 I am working in WordPress. Please be more specific as I don't follow. Quote Link to comment https://forums.phpfreaks.com/topic/315135-php-isnt-targeting-guest-customers-in-woocommerce/page/3/#findComment-1599030 Share on other sites More sharing options...
maxxd Posted August 5, 2022 Share Posted August 5, 2022 This may help: https://wholesalesuiteplugin.com/kb/how-to-hide-prices-for-not-logged-in-customers-guests/ Quote Link to comment https://forums.phpfreaks.com/topic/315135-php-isnt-targeting-guest-customers-in-woocommerce/page/3/#findComment-1599042 Share on other sites More sharing options...
martini0 Posted August 8, 2022 Author Share Posted August 8, 2022 I have got the fix! add_filter( 'woocommerce_package_rates', 'shipping_methods_based_on_wholesale_customer', 10, 2 ); function shipping_methods_based_on_wholesale_customer( $rates, $package ) { $user = wp_get_current_user(); $roles = (array) $user->roles; // Set the shipping methods rate ids in the arrays. if ( ! in_array( 'wholesale_customer', $roles, true ) ) { $shipping_rates_ids = array( 'flat_rate:10', 'flat_rate:7' ); // To be removed for NON Wholesale users. } else { $shipping_rates_ids = array( 'flat_rate:13', 'flat_rate:15' ); // To be removed for Wholesale users. } // Loop through shipping rates from the current shipping package. foreach ( $rates as $rate_key => $rate ) { if ( in_array( $rate_key, $shipping_rates_ids, true ) ) { unset( $rates[ $rate_key ] ); } } return $rates; } Quote Quote Quote Link to comment https://forums.phpfreaks.com/topic/315135-php-isnt-targeting-guest-customers-in-woocommerce/page/3/#findComment-1599161 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.