• Rhand

    (@rhand)


    We are currently using this code to allow customers to buy max 5 items of products. It seem to work in the sense that once they add 6 is idles for a while and then shows 5 items were added and not more. Is this the way the filter works? Is there a way to just not allow the usage of let’s say 6? Two, is it normal for the system to stall? Are there specific memory needs perhaps?

    // max 5 items for admin and customer
    // added 5.5 and 5 were added
    
    add_filter( 'alg_wc_pq_max_product_qty', 'my_product_qty_max_by_user_role', 10, 2 );
    function my_product_qty_max_by_user_role( $qty, $product_id ) {
    	$current_user = wp_get_current_user();
    	return ( in_array( 'customer, administrator', $current_user->roles ) ? 10 : $qty );
    }

    We would

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Omar AlDabbas

    (@omardabbas)

    Hi @rhand,

    I’m not sure if I got you correctly here, but I think you want to prevent adding 6 to the cart.

    The plugin allows you to either deny adding to cart, or allowing that with fixing the amount, or even blocking the checkout page (all available in plugin main page).

    If you can rephrase the question and possibly adding a link to the issue, I would love to offer more help.

    Omar

    Thread Starter Rhand

    (@rhand)

    I wanted to prevent adding more than five to cart for role customer. And for role company minimum 10.

    We now use minimum 10 items for company:

    add_filter( 'alg_wc_pq_get_product_qty_min', 'my_product_qty_min_by_user_role', 10, 2 );
    function my_product_qty_min_by_user_role( $qty, $product_id ) {
    	$current_user = wp_get_current_user();
    	return ( in_array( 'bedrijf', $current_user->roles ) ? 10 : $qty );
    }

    and max 50 for company:

    
    add_filter( 'alg_wc_pq_get_product_qty_max', 'my_product_qty_max_by_user_role', 10, 2 );
    function my_product_qty_max_by_user_role( $qty, $product_id ) {
    	$current_user = wp_get_current_user();
    	return ( in_array( 'bedrijf', $current_user->roles ) ? 50 : $qty );
    }

    for company quantity steps we use 10:

    add_filter( 'alg_wc_pq_get_product_qty_step', 'my_product_qty_step_by_user_role', 10, 2 );
    function my_product_qty_step_by_user_role( $qty, $product_id ) {
    	$current_user = wp_get_current_user();
    	return ( in_array( 'bedrijf', $current_user->roles ) ? 10 : $qty );
    }

    This seems to work quite well now. For customer we have not added code yet / commented out code as we were having issues.

    • This reply was modified 5 years ago by Rhand.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Max No of Items Filter Idling and Inner Workings’ is closed to new replies.