0

I have added a maximum quantity field under the General menu of the product data. After I set a maximum if I add more than the maximum to the cart I get the desired error and the number of items can't be increased in the cart (via the product page). However from the cart page the number can be increased through the scrolling field. I cannot find a way to disable that action by assigning the product ID associated with my my_max_quantity meta field..

I have seen ways to disable the field for all products but can't find the method to do it for a particular product.

I found this function at funnelkit.com that supposed to disable all the quantity in the cart but maybe it's for an older version of WooCommerce:


function disable_cart_item_quantity( $product_quantity, $cart_item_key, $cart_item ) {
    if ( is_cart() ) {
        $product_quantity = sprintf( '<strong>%s</strong><input type="hidden" name="cart[%s][qty]" value="%s" />', $cart_item['quantity'], $cart_item_key, $cart_item['quantity'] );
    }
    return $product_quantity;
}

I tried to see if it could be adjusted to disable the quantity on a single product with the following altered code but with no luck:

    // Product ID for which to disable quantity changes
    $disable_quantity_product_id = 23;

    if ( is_cart() && $cart_item['product_id'] === $disable_quantity_product_id ) {
        $product_quantity = sprintf( '<strong>%s</strong><input type="hidden" name="cart[%s][qty]" value="%s" />', $cart_item['quantity'], $cart_item_key, $cart_item['quantity'] );
    }

    return $product_quantity;
}

After the product is added to the cart, it seems as if it becomes inaccessible except to change the quantity or delete the item with the built in methods. Is there a way to prevent the visitor increasing the quantity of a specific product after it has been added to the cart?

Thanks.

1
  • You'll have to ask WooCommerce's support team about this. Third-party plugin support is off topic here.
    – Pat J
    Commented 11 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.