Support » Plugin: WooCommerce Cart Stock Reducer » Limit the plugin only to some customers

  • Resolved SYNC4489

    (@sync4489)


    Hi,

    we would like to know how hard should it be to customize the plugin to limit its functionality only for one or few particular customers…

    After I’ve added this additional condition at line 45 of class-woocommerce-cart-stock-reducer.php ( 9 is the customer ID for which I want the plugin to reduce immediately the stock when he adds to cart ) things work but exactly the opposite that I need: stock is reduced by any customer excepted for ID 9…

    if ( 'yes' === $this->cart_stock_reducer && 9 == get_current_user_id() )

    If you have any idea it would be greatly appreciated πŸ™‚

    BTW, I’m on WP 4.9.7 and WC 3.4.4

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author James Golovich

    (@jamesgol)

    Can you give a little bit more information about what exactly you are trying to accomplish?

    If you have some items that are limited quantity but only expire for certain users then you still have the potential for the items to be completely reserved by those users and never available.

    Perhaps a long expiration time for everyone and then a shorter expiration time for those specific users would be best?

    While I don’t think anyone has done anything like this before, there are some WordPress filters that could be used to adjust the behavior. The most likely one would be ‘wc_csr_expire_time_text’. Here is where the filter is called

    The function can return an alternate expiration time ’10 minutes’, ‘1 hour’, etc. or even ‘never’ and then the item will never expire from the users cart.

    I certainly wouldn’t recommend modifying the code, you’ll only lose your changes when a new version is released. If you really want this plugin to only run for specific users you could try adding an early hook on the ‘woocommerce_integrations’ action that checks the user id and if it’s not in the list remove the action that starts it all.

    Hi James, thanks for your fast reply πŸ™‚

    I’ll try to explain better my need. In fact I don’t need at all any expiration time, countdown or other fancy nice things.

    The purpose of this modification is because we have a very few VIP local customers who have their shops very near our facility, that during the day will come and get spare parts that we sell, every time they need it, from morning to evening.
    And at the end of the day they place the final order for all the pieces they bought during the day, and they pay us.

    But we have to manually reduce quantity every time they come to avoid possibility to oversell the stock during the day… or otherwise they should place an order every time they need a spare part and come to our store.

    So to have your plugin work only for these very few customers (just the functionality of stock manipulation as soon as they add/update/remove from cart), would be of great help. They could start their cart in the morning, adding items the whole day, and at the end of the day just place the order.

    Do you think that it could be possible with your plugin?

    Plugin Author James Golovich

    (@jamesgol)

    Interesting usage case. Let me ask a few more questions to see if I can figure out the best way to do it.

    So your VIP customers will drop in at various times during the day and pickup parts and only at the end of the day is the order paid for and closed out? I assume you don’t want to have individual orders each time they come in.

    When a VIP customer comes in are they pre adding an item to their cart before they come in or they just show up and if you have the item then they take the item and you deal with your inventory problem?

    Then you have non VIP customers that place orders online and have the parts shipped to them (or scheduled pickup)? How do you handle stock for these users?

    I’m sure there is a way to do this and it might not even involve my plugin at all, but that would depend on the whole workflow. For example if you are doing the backend work for the VIP customers, you could create an order from them and set it in the pending state (set the WooCommerce Hold Stock setting to something like 24 hours). This should reduce the quantity of the stock and will leave the order unpaid and the customer can later login and actually pay for the order.

    Hi again πŸ™‚

    So your VIP customers will drop in at various times during the day and pickup parts and only at the end of the day is the order paid for and closed out? I assume you don’t want to have individual orders each time they come in.

    Right, this is exactly the scenario

    When a VIP customer comes in are they pre adding an item to their cart before they come in or they just show up and if you have the item then they take the item and you deal with your inventory problem?

    They check if the item is available on our website, and if it is they come as they are at less than 50 meters away…
    So we have to write down what they take, and manually reduce the stock on WC.
    At the end of the day they take a copy of our paper, enter the whole order, place it, and pay.

    Then you have non VIP customers that place orders online and have the parts shipped to them (or scheduled pickup)? How do you handle stock for these users?

    Yes we have literally hundreds of online customers to who we ship. Stock is reduced only when the order is placed. Adding to cart doesn’t make any kind of “item reservation”…

    So what we try to accomplish is that only for very specific customers we have to change stock immediately when they add/remove/update to cart, so we could eliminate all the manual process.
    The customer could start his cart in the morning, add items to it during the day when they come to pick it up, and simply close the order and pay on the evening and we could automatically avoid any overselling to our online customers.

    • This reply was modified 7 months, 3 weeks ago by  SYNC4489.

    I’ve just made this modification to woocommerce-cart-stock-reducer.php

    if ( ! defined( 'ABSPATH' ) ) exit;
    
    function make_cart_stock_reducer_go_now( $integrations = array() ) {
    	if ( class_exists( 'WC_Integration' ) ) {
    		// Three... Two... One... MAKE ROCKET GO NOW!
            if ( 9 != get_current_user_id() ) {
    		  require_once plugin_dir_path( __FILE__ ) . 'includes/class-woocommerce-cart-stock-reducer.php';
    		  $integrations[] = 'WC_Cart_Stock_Reducer';
    		  return $integrations;
            } else {
                return false;
            }
    	}
    }

    and it works except for a weird quirk… now the “VIP” customer (ID 9) never sees the “out of stock” availability and can always put in the cart any item, with stock going below zero, even if our woocommerce is configured to forbid any backorder…

    Plugin Author James Golovich

    (@jamesgol)

    I can think of two possible solutions (there are likely many others).

    1. Don’t use this plugin, but when your VIP customer comes in to get something create a manual order on the backend, then if they come and get more items just edit the order. At the end of the day they can login and pay for the pending order
    2. Use this plugin, but use it for everyone. Set the VIP customers items to expire ‘never’ with the ‘wc_csr_expire_time_text’ filter. This should keep your inventory from getting out of sync.
    
    add_filter('wc_csr_expire_time_text', 'vip_wc_csr_expire_time', 10, 4 );
    function vip_wc_csr_expire_time( $text, $item, $key, $csr ) {
        if (9 === get_current_user_id()) {
            $text = 'never';
        }
        return $text;
    }
    

    Hi again James,

    solution 1 is not really not interesting because it involves anyway a manual job and also because these customers have special “role” prices, loyalty points, coupons, that are impossible to manage without making manual discounts and calculations on the backend order after it has been placed.
    In this case we’d simply stick with our actual manual solution…

    solution 2 could have been nice… but:
    the filter as it is apparently does not work: I’ve inserted it as a snippet, activated in your plugin the expiration at 1 minute, logged in with a normal user in a browser and with our famous “user 9” in another, after 1 minute both users had the cart items removed.
    And I’ve just figured out that doing so, normal users would have their items physically removed from cart! This would be a no-no situation for us, sometimes some of our online customers build their cart in the span of 2-3 days!

    The best solution, let’s call it number 3, would simply be to be able to activate the stock reducing function only for one or a few users, no expiry (and it should respect the out of stock status/backorder setting).
    For all the others, the plugin would be just completely “turned off”.

    If you’re interested we could even arrange a paid customization job for this modification…

    Let me know, and of course thanks for all the time you’re spending to find a suitable solution for us

    Plugin Author James Golovich

    (@jamesgol)

    The solution number 3 would involve a completely different type of plugin. The way this plugin actually works is the actually inventory is not reduced but when the inventory is checked by WooCommerce it “virtually” reduces it based on quantity in the cart. So if you are going to use it at all it has to be on for everyone or else the users with the plugin disabled will always see the real inventory stock and the users with the plugin enabled will see the “virtual” inventory stock.

    Additionally, the expiration time is set on the item when it is added in the cart. So if you activated that filter after the item was added it would respect the expiration time set when the item was added.

    By default WooCommerce clears carts/sessions after 48 hours of no activity. You could set the cart expiration timer for everyone to some arbitrarily long time (3-7 days) and then at least there would be some eventual cleanup of the inventory if the users just abandon their cart. You could also just disable the expiration time completely and then the items will return their stock when the cart is expired by WooCommerce.

    I’d be happy to help build a custom solution or get this working properly, feel free to contact me directly <james@gnuinter.net>

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Limit the plugin only to some customers’ is closed to new replies.