Dalibor Votruba 253d86e1fc studiou-wc-mandatory-products: fix readme.md 1 年間 前
..
assets 324c18d764 studiou-wc-mandatory-products: fix adding product in product category edit. 1 年間 前
includes 324c18d764 studiou-wc-mandatory-products: fix adding product in product category edit. 1 年間 前
languages e3b5ff4b27 studiou-wc-mandatory-products: add localizations, but some text are not translated 1 年間 前
directory-structure.txt e3b5ff4b27 studiou-wc-mandatory-products: add localizations, but some text are not translated 1 年間 前
instructions.txt 1fa60b8405 add studiou-wc-mandatory-products 1 年間 前
readme.md 253d86e1fc studiou-wc-mandatory-products: fix readme.md 1 年間 前
studiou-wc-mandatory-products.php 5934cdaf5b studiou-wc-mandatory-products: fix check if constants already defined, add localizations 1 年間 前

readme.md

QDR - Studiou WC Mandatory Products

Version: 1.1.1

A WordPress plugin that extends WooCommerce to add mandatory products to cart based on product categories.

Description

StudioU WC Mandatory Products allows store administrators to define mandatory products at the category level. When a customer adds a product from a configured category to their cart, the mandatory products are automatically added as well.

Key Features

  • Extend WooCommerce Product Categories with mandatory product settings
  • Automatic addition of mandatory products to cart
  • Support for parent-child category inheritance
  • Two types of mandatory product behavior:
    • OnePerCart: Add once per cart
    • OnePerProduct: Add once for each product that requires it
  • Visual indicators for mandatory products in cart
  • Non-removable mandatory products in cart
  • Admin meta box showing mandatory products for a given product

Installation

  1. Upload the studiou-wc-mandatory-products folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Ensure WooCommerce is installed and activated

Requirements

  • WordPress 6.7.2 or higher
  • WooCommerce 3.0 or higher
  • PHP 8.2 or higher

This plugin is compatible with WooCommerce's High-Performance Order Storage (HPOS) feature.

Usage

Setting Up Mandatory Products

  1. Navigate to Products > Categories in your WordPress admin
  2. Edit an existing category or create a new one
  3. Scroll down to the Mandatory Products section
  4. Click the "Add Mandatory Product" button
  5. Search for and select a product that should be mandatory
  6. Set the quantity and type:
    • OnePerCart: Add only once per cart
    • OnePerProduct: Add once for each product from this category
  7. Save the category

Inheritance

Child categories automatically inherit the mandatory product settings from their parent categories. This makes it easy to set up mandatory products at a high level and have them apply to all subcategories.

Example Scenario

Product categories tree:

  • Main Category
    • SubCategory1
    • SubCategory2

Products:

  • MandatoryProduct1 (In Main Category)
  • ProductA (In SubCategory1)
  • ProductB (In SubCategory2)

Settings:

  • Main Category
    • Mandatory Products: MandatoryProduct1, amount: 1, type: OnePerCart

User Ordering:

  1. Add to cart ProductA (10pcs)
  2. Add to cart ProductB (2pcs)
  3. Cart will contain:
    • ProductA (10pcs)
    • ProductB (2pcs)
    • MandatoryProduct1 (1pc) - Automatically added

How It Works

When a customer adds a product to their cart, the plugin checks if the product's category (or any parent category) has mandatory products configured. If it does, those mandatory products are automatically added to the cart based on the specified rules.

Mandatory products in the cart are:

  • Clearly marked as mandatory
  • Cannot be removed directly (customer must remove the original product)
  • Cannot have their quantity changed

Customization

CSS

The plugin includes basic styles for the frontend, which you can override in your theme's stylesheet.

Hooks and Filters

Developers can use the following hooks to extend or modify the plugin's functionality:

  • studiou_wcmp_before_add_mandatory_products: Fires before mandatory products are added to cart
  • studiou_wcmp_after_add_mandatory_products: Fires after mandatory products are added to cart
  • studiou_wcmp_get_mandatory_products: Filter to modify the list of mandatory products for a given product

Frequently Asked Questions

Can I make a variable product mandatory?

Yes, you can select any product type as a mandatory product, including variable products. However, the plugin will add the default variation if no specific variation is selected.

Can customers remove mandatory products from cart?

No, mandatory products cannot be removed directly. They will be removed automatically when the product that triggered their addition is removed.

Will mandatory products inherit quantity from the main product?

No, mandatory products will be added with the quantity specified in the category settings, regardless of how many of the main product are added to the cart.

Support

For support requests, please contact us at https://www.quadarax.com or open an issue on our GitHub repository.

License

This plugin is licensed under the GPL v2 or later.

Credits

Developed by Dalibor Votruba (Quadarax)