Dokan WordPress Marketplace Plugin

repository·develop·Indexed 43 days ago

https://github.com/getdokan/dokan

A multivendor marketplace plugin for WordPress built on top of WooCommerce, enabling the creation of marketplaces similar to Amazon or eBay. Version 5.1.2 includes developer tools for extending the admin onboarding setup, creating custom field types with React, and implementing new admin dashboard pages by extending the AbstractPage class.

Tokens
120.6K
Snippets
273
Records
402
Agent score
55%

What's inside Dokan

  1. Dokan Multivendor Marketplace Overview

    develop
    Dokan is an AI-powered WooCommerce multivendor marketplace solution for WordPress. It allows users to transform a standard WooCommerce site into a marketplace where multiple vendors can sell physical products, digital downloads, bookings, auctions, or subscriptions. It is designed to function without requiring custom code development.
  2. What is Stripe Express Sandbox Mode?

    develop

    Stripe Express Sandbox Mode is a dedicated testing environment designed for safe, isolated payment simulation.

    Key characteristics:

    • Isolation: It is completely separate from standard Stripe Test Mode and Live Mode. It does not interact with real funds or existing test/production data.
    • Credentials: It requires unique Sandbox API keys and webhook secrets obtained from a Stripe sandbox account, rather than standard Stripe test keys.
    • Use Case: Ideal for QA, development, or staging environments where you need to test complex payment flows and webhooks without polluting your primary Stripe data.
  3. Implement Dashboard Tables with DataViews

    develop

    All tabular data in the Dokan dashboard must be implemented using the DataViews component from @dokan/components.

    Standard Requirements:

    • Table Actions: Row actions must be displayed as text links rather than icons.
    • Destructive Actions: Any action that deletes data (e.g., Delete) must be accompanied by a Confirmation Modal.
  4. How the Dokan export system architecture works

    develop

    The Dokan export system integrates with WooCommerce's export functionality to allow for report generation of any Dokan data type. It relies on three core components:

    1. ExportController: A REST API controller that extends WooCommerce's Export Controller to handle the API requests.
    2. ExportableController: Individual report controllers that implement the ExportableInterface to define what data is exported.
    3. Registration: The mechanism using filter hooks to register these controllers into the system.

    All exports are processed in the background using WooCommerce's Action Scheduler to prevent timeouts during large data exports.

  5. How coupon removal works from Orders

    develop

    When a WC_Order_Item_Coupon is deleted, Dokan executes a removal flow to ensure discount consistency across related orders.

    The removal process follows these steps:

    1. Initialize WC_Order_Item_Coupon with the $item_id.
    2. If an Order ID exists, retrieve the coupon code and the order.
    3. Remove the coupon discount from the current order items.
    4. Handle related orders:
      • If the order has sub-orders, the coupon is removed from all child orders.
      • If there are no sub-orders, check for a parent order. If a parent exists, the system filters parent items with matching product IDs and removes the coupon discount from those matching items.

    This logic is located in includes/Vendor/Coupon.php (Lite edition).

  6. Customize DokanModal with dynamic content and styling

    develop

    The DokanModal component allows for deep customization through dynamic content elements and styling props:

    Dynamic Content Elements

    You can pass custom JSX elements to override specific parts of the modal structure:

    • dialogIcon: A custom icon element for the modal header.
    • dialogHeader: A custom header component.
    • dialogContent: Custom content for the modal body.
    • dialogFooter: Custom button or footer contents.
    • dialogTitle: Custom title for the modal dialog.

    Styling and Identification

    • Custom Styling: Use the className prop to apply additional CSS classes for UI customization.
    • Namespace: A unique namespace is required for each instance to ensure proper identification and styling isolation.
  7. Understand the Dokan repository architecture

    develop

    Dokan is organized into several key directories to separate concerns:

    • assets/: Frontend and admin assets (CSS, JS, images, and source files).
    • includes/: Core PHP functionality, including Admin-specific code and global functions.
    • templates/: Frontend template files for dashboards, global elements, emails, and settings.
    • src/: Source files for React and Vue frontend code (components, hooks, utilities, and admin code).
    • tests/: Test suites containing PHPUnit and Playwright tests.
    • lib/: Third-party libraries and dependencies.
    • docs/: Developer documentation.
    • languages/: Translation files.
  8. Understand Order and Suborder relationships

    develop

    Dokan distinguishes between the customer's view of a purchase and the vendor's operational view:

    • Order: The WooCommerce order as seen by the customer. It may contain products from multiple vendors. Operational effects like stock and commission happen at the Suborder/Vendor order level, not here.
    • Suborder: A per-vendor order split from a multi-vendor Order. Single-vendor Orders do not have Suborders.
    • Vendor order: The specific unit a Vendor processes and earns commission on. This is either the Suborder (in multi-vendor orders) or the Order itself (in single-vendor orders).

    Note on Refunds: A Refund is recorded against a Vendor order and mirrored to the parent Order. Creating a refund directly on a parent Order is outside the standard model and will not be seen by vendor accounting.

  9. Implement services in a Service Provider

    develop

    When creating a service provider, you must implement two methods: provides and register.

    • provides(string $id): bool: This method tells the container which service IDs or class names this provider is responsible for. If the $id is not returned as true here, the container will ignore any registration attempts for that ID in the register method.
    • register(): void: This method is used to define the actual services within the container using the container instance obtained via $this->getContainer().
    namespace WeDevs\Dokan\DependencyManagement\Providers;
    
    use WeDevs\Dokan\BaseServiceProvider;
    
    class SomeServiceProvider extends BaseServiceProvider
    {
        public function provides(string $id): bool
        {
            $services = [
                'key',
                Some\Controller::class,
                Some\Model::class,
                Some\Request::class,
            ];
    
            return in_array($id, $services);
        }
    
        public function register(): void
        {
            $this->getContainer()->add('key', 'value');
    
            $this->getContainer()
                ->add(Some\Controller::class)
                ->addArgument(Some\Request::class)
                ->addArgument(Some\Model::class);
    
            $this->getContainer()->add(Some\Request::class);
            $this->getContainer()->add(Some\Model::class);
        }
    }
  10. Handle refunds in a multi-vendor order environment

    develop

    Refunds must be initiated at the vendor order (suborder) level to ensure correct vendor accounting.

    Refund Workflow:

    1. Initiation: A refund is created against the specific vendor order.
    2. Mirroring: The refund is mirrored up to the parent order.
    3. Pro Version Behavior: In Dokan Pro, the system maps the suborder's line items onto a matching parent refund, ensuring the payment gateway is charged only once at the parent level.

    Critical Warning: Creating a refund directly against a parent order is unsupported by the model. Vendor accounting will ignore refunds created at the parent level in both Dokan Lite and Pro.

  11. How Dokan REST Controllers work

    develop

    Dokan REST Controllers provide a structured way to manage REST API endpoints with built-in role-based permissions. Instead of extending the standard WP_REST_Controller directly, Dokan uses a hierarchy of base controllers to automatically handle permissions for different user roles.

    The hierarchy is as follows:

    • DokanBaseController: The root base controller.
    • DokanBaseAdminController: For administrative endpoints.
    • DokanBaseVendorController: For vendor-specific endpoints.
    • DokanBaseCustomerController: For customer-specific endpoints.

    By extending these, your custom endpoints inherit the appropriate permission logic for the intended user role.