WP Manifestindependent plugin directory
manifest / ecommerce / woocommerce-cart-quantity-limits

WooCommerce Cart Quantity Limits

Limits the quantity of each product and the number of unique products allowed in the WooCommerce cart.

by Amirreza Shayesteh Far · github.com/amirrezashf/woocommerce-cart-quantity-limits · website

★ 0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/amirrezashf/woocommerce-cart-quantity-limits/archive/refs/heads/main.zip

Limits the quantity of each product and the number of unique products allowed in the WooCommerce cart.

Description

WooCommerce Cart Quantity Limits applies two independent cart restrictions:

  • Maximum quantity of each product: 20
  • Maximum number of unique products: 10

The validation applies when products are added to the cart and when quantities are changed inside the cart.

By default, all variations of one variable product are treated as one product for both limits.

Features

  • Maximum quantity per product
  • Maximum unique products per cart
  • Add-to-cart validation
  • Cart quantity-update validation
  • Supports simple products
  • Supports variable products
  • Combines quantities from duplicate cart rows
  • Treats variations as their parent product by default
  • Supports custom cart-item data
  • Persian error messages and digits
  • Configurable limits through filters
  • HPOS compatible
  • No custom database tables
  • Single-file plugin architecture

Requirements

  • PHP 7.4+
  • WordPress 6.0+
  • WooCommerce

Installation

  1. Download the repository as a ZIP file.
  2. Open Plugins → Add New Plugin → Upload Plugin.
  3. Upload the ZIP file.
  4. Install and activate the plugin.

Default Limits

Maximum per product: 20
Maximum unique products: 10

Set either value to 0 through its filter to disable that limit.

How Products Are Counted

Quantity limit

All cart rows belonging to the same target product are added together.

For example, if the same product appears in two cart rows with quantities 8 and 7, its current total is 15.

Unique-product limit

The plugin counts unique target product IDs, not raw cart rows. Custom cart-item data therefore does not artificially increase the unique-product count.

Variations

By default, all variations of one variable product share:

  • One quantity limit
  • One unique-product slot

This matches the original parent-product behavior.

Filters

wc_cql_maximum_per_product

Changes the maximum quantity for each product.

add_filter(
    'wc_cql_maximum_per_product',
    static function ( $maximum, $product_id ) {
        if ( 123 === $product_id ) {
            return 5;
        }

        return 20;
    },
    10,
    2
);

Return 0 to disable the per-product limit.

wc_cql_maximum_unique_products

Changes the maximum number of unique products.

add_filter(
    'wc_cql_maximum_unique_products',
    static function () {
        return 15;
    }
);

Return 0 to disable the unique-product limit.

wc_cql_limit_target_id

Changes how products and variations are grouped.

To treat each variation as a separate product:

add_filter(
    'wc_cql_limit_target_id',
    static function ( $target_id, $product_id, $variation_id ) {
        return $variation_id > 0 ? $variation_id : $product_id;
    },
    10,
    3
);

Security and Reliability

The plugin:

  • Validates both add-to-cart and cart-update requests
  • Uses WooCommerce cart APIs
  • Avoids direct database queries
  • Does not trust the raw number of cart rows
  • Supports duplicate rows created by custom cart-item data
  • Does not create custom database tables
  • Does not send external requests

HPOS Compatibility

The plugin declares compatibility with WooCommerce High-Performance Order Storage. It does not query order storage directly.

Changelog

1.0.0

  • Initial release
  • Added per-product quantity limit
  • Added unique-product cart limit
  • Added cart-update validation
  • Added variable-product grouping
  • Added configurable filters
  • Added HPOS compatibility

License

GPL-3.0

Author

Amirreza Shayesteh Far


محدودیت تعداد محصولات سبد خرید ووکامرس

محدود کردن تعداد هر محصول و تعداد محصولات مختلف موجود در سبد خرید ووکامرس.

توضیحات

افزونه WooCommerce Cart Quantity Limits دو محدودیت مستقل روی سبد خرید اعمال می‌کند:

  • حداکثر تعداد هر محصول: ۲۰ عدد
  • حداکثر تعداد محصولات مختلف: ۱۰ محصول

اعتبارسنجی هم هنگام افزودن محصول و هم هنگام تغییر تعداد محصول داخل سبد خرید انجام می‌شود.

به‌صورت پیش‌فرض تمام variationهای یک محصول متغیر، یک محصول در نظر گرفته می‌شوند.

ویژگی‌ها

  • محدودیت حداکثر تعداد هر محصول
  • محدودیت تعداد محصولات مختلف
  • اعتبارسنجی افزودن به سبد
  • اعتبارسنجی تغییر تعداد در سبد
  • پشتیبانی از محصولات ساده
  • پشتیبانی از محصولات متغیر
  • جمع کردن تعداد ردیف‌های تکراری یک محصول
  • درنظرگرفتن variationها به‌عنوان محصول والد
  • پشتیبانی از cart item data سفارشی
  • پیام خطای فارسی با اعداد فارسی
  • محدودیت‌های قابل تنظیم با filter
  • سازگاری با HPOS
  • بدون جدول اختصاصی دیتابیس
  • معماری تک‌فایلی

نیازمندی‌ها

  • PHP 7.4 یا جدیدتر
  • WordPress 6.0 یا جدیدتر
  • WooCommerce

نصب

  1. repository را به‌صورت ZIP دانلود کنید.
  2. وارد افزونه‌ها ← افزودن افزونه تازه ← بارگذاری افزونه شوید.
  3. فایل ZIP را بارگذاری کنید.
  4. افزونه را نصب و فعال کنید.

محدودیت‌های پیش‌فرض

حداکثر تعداد هر محصول: ۲۰
حداکثر محصولات مختلف: ۱۰

برای غیرفعال کردن هر محدودیت، مقدار آن را با filter برابر 0 قرار دهید.

روش شمارش محصولات

محدودیت تعداد

تعداد تمام ردیف‌های سبد که به یک محصول هدف مربوط هستند با هم جمع می‌شود.

برای مثال، اگر یک محصول در دو ردیف با تعدادهای ۸ و ۷ وجود داشته باشد، تعداد فعلی آن ۱۵ در نظر گرفته می‌شود.

محدودیت محصولات مختلف

افزونه شناسه محصولات یکتا را می‌شمارد، نه تعداد خام ردیف‌های سبد. بنابراین cart item data سفارشی باعث افزایش اشتباه تعداد محصولات مختلف نمی‌شود.

Variationها

به‌صورت پیش‌فرض تمام variationهای یک محصول متغیر دارای موارد مشترک زیر هستند:

  • یک محدودیت تعداد
  • یک جایگاه در شمارش محصولات مختلف

فیلترها

wc_cql_maximum_per_product

تغییر حداکثر تعداد هر محصول:

add_filter(
    'wc_cql_maximum_per_product',
    static function ( $maximum, $product_id ) {
        if ( 123 === $product_id ) {
            return 5;
        }

        return 20;
    },
    10,
    2
);

برای غیرفعال کردن این محدودیت مقدار 0 برگردانید.

wc_cql_maximum_unique_products

تغییر حداکثر تعداد محصولات مختلف:

add_filter(
    'wc_cql_maximum_unique_products',
    static function () {
        return 15;
    }
);

wc_cql_limit_target_id

تغییر نحوه گروه‌بندی محصول و variation:

برای اینکه هر variation یک محصول جداگانه محسوب شود:

add_filter(
    'wc_cql_limit_target_id',
    static function ( $target_id, $product_id, $variation_id ) {
        return $variation_id > 0 ? $variation_id : $product_id;
    },
    10,
    3
);

امنیت و پایداری

افزونه:

  • افزودن محصول و تغییر تعداد را اعتبارسنجی می‌کند
  • از API رسمی سبد خرید ووکامرس استفاده می‌کند
  • SQL مستقیم ندارد
  • به تعداد خام ردیف‌های سبد متکی نیست
  • ردیف‌های تکراری ناشی از اطلاعات سفارشی را درست مدیریت می‌کند
  • جدول اختصاصی ایجاد نمی‌کند
  • درخواست خارجی ندارد

سازگاری با HPOS

افزونه سازگاری خود را با WooCommerce High-Performance Order Storage اعلام می‌کند و مستقیماً به ساختار ذخیره‌سازی سفارش‌ها وابسته نیست.

تغییرات نسخه‌ها

1.0.0

  • انتشار اولیه
  • افزودن محدودیت تعداد هر محصول
  • افزودن محدودیت محصولات مختلف
  • اعتبارسنجی تغییر تعداد سبد
  • گروه‌بندی محصولات متغیر
  • افزودن filterهای تنظیمات
  • سازگاری با HPOS

مجوز

GPL-3.0

نویسنده

Amirreza Shayesteh Far