Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by martini0

  1. 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; }
  2. I am working in WordPress. Please be more specific as I don't follow.
  3. 1. I have paste the code in functions.php 2. Where should I see the output? I am working in WordPress. 3. Not sure if I am allowed to ask this here, if not, I will erase point 3. Would someone be willing to debug and make the code work? As a gesture, I can make a donation. 🙂 Please tell me if I am not allowed to post this here.
  4. I must be super annoying, I am so sorry. The code is in my functions.php. It is saved and works. Now where do I find that output?
  5. I have placed the code in functions.php. And saved. All works. So now where can I find that contents of your $rates array? Is that within Directadmin.
  6. Tried it, but not working. It isn't removing any shipment options for both guest as for logged in users.
  7. Via WooCommerce Wholesale Prices -> it makes a new user ID which is wholesale_customer
  8. $is_wholesale = get_user_meta( 153, 'wholesale_customer', true ); -> tried but no effect. Does someone know a work around? Maybe when the code checks for logged in user, it works. But how? It doesn't have to target wholesale_customers only. Because only wholesale_customer needs to log in. Nobody else can log in. Could someone change the code to check for logged in, or not logged in?
  9. $is_wholesale = get_user_meta( 'user_id=153', 'wholesale_customer', true ); is this correct?
  10. Not the actual ID. Good point. Let me try with an Actual ID
  11. $is_wholesale = get_user_meta( 'A_USER_ID', 'wholesale_customer', true ); -> I tried, no effect. Could you rewrite the code to target ALL logged in user? So not only wholesale_customers.
  12. So I tried a second piece of code. Same issue. It isn't targeting wholesale_users. IT just removed the flat_rate:13 for ALL users guest, subscribers, and wholesale_users. /** * Removes shipping methods for non-wholesale customers. * Please be sure to clear your WooCommerce store's cache. * Adjust 'flat_rate:2' to match that of your wholesale shipping method. */ function my_wcs_remove_shipping_non_wholesale( $rates, $package ){ global $current_user; $is_wholesale = get_user_meta( $current_user->ID, 'wholesale_customer', true ); if ( ! $is_wholesale ) { foreach( $rates as $method ) { if ( $method->id == 'flat_rate:13') { unset( $rates[$method->id] ); } } } return $rates; } add_filter( 'woocommerce_package_rates', 'my_wcs_remove_shipping_non_wholesale', 10, 2 ); This is how I setup my shipment zones. Is that correct? So within 1 zone, 2 options for paid shipment and 2 options for free shipment.
  13. Does it help if I post my website? Can I do it securely? OK 1. All wholesale users have the wp_capabilities: array ( 0 => array ( 'wholesale_customer' => true, 'bbp_participant' => true, ), ) 2. "no effect"??? Let me clarify as detailed as possible. I have changed 'wholesale_customer', true ); -> 'translator', true ); BUT then still GUEST (NON LOGGED IN) are NOT seeing: flat_rate:13 and flat_rate:15. The code is thus always removing both flat_rates13 and 15. *I will actually 100% donate you if we are able to fix. Or I can send a gift card for our shop. We design babyitems. Hold on, I have more info!
  14. Could you help me re write it to target logged in users?
  15. 1. I just copied the code from stackoverflow and edited with my own flat rate information 2. Im not a programmer, I dont know how to do... 3. I have just now tested it with the ID: 'translator' and no effect. Also I have removed all other PHP and tested. No effect. 4. I don't know how...
  16. How can I make my code work for ALL logged in users? Maybe that works. add_filter( 'woocommerce_package_rates', 'shipping_methods_based_on_wholesale_customer', 10, 2 ); function shipping_methods_based_on_wholesale_customer( $rates, $package ){ $is_wholesale = get_user_meta( get_current_user_id(), 'wholesale_customer', true ); // Set the shipping methods rate ids in the arrays: if( $is_wholesale ) { $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) ) { unset( $rates[$rate_key] ); } } return $rates; }
  17. Oh wait, thanks! Let me try that first thing in the morning 🙂 thanks a lot.
  18. I know what to do when the code breaks.. and I always test the code for issues on a PHP code tester.
  19. Because I try not to be a quitter.. 🙂 I am a small business owner and design babyitems.
  20. Could you please update the code so that it is working? I have lost 2 days trying things, as I am not a programmer. You would honestly, not joking, be my hero.
  21. Show you that function? Do you mean another code? I got the code from here. Do I also need to add other code then the one mentioned above? I am no programmer, so not that experienced.
  22. $is_wholesale is always returning true, but why? wholesale_user is a valid user type.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.