Hello guys how are you? Welcome back to my blog therichpost.com. Guys today in this post, I will tell you How to Automatically Disable Vendors After Subscription Cancellation? Dokan Multi vendor.
Guys if you are new in WordPress or in WooCommerce then please check the below links for some good tutorials:
In Dokan Multivendor, vendors are not automatically disabled from selling when their subscription is canceled because the platform doesn’t enforce an automatic connection between subscription status and vendor capabilities out of the box. This behavior is often intentional to provide flexibility, as different marketplaces may have varying requirements for handling subscriptions and vendor statuses.
Common Reasons for Lack of Automatic Disabling
- Flexibility for Vendors:
- Vendors might need a grace period to renew their subscription.
- Automatic disabling could disrupt legitimate business operations.
- Custom Subscription Management Needs:
- Dokan does not assume how you want to handle vendor status after a subscription ends since marketplaces have different policies.
- Manual Intervention Preferred:
- Some marketplace administrators prefer to manually review and disable vendors, especially if there are ongoing payments, disputes, or renewals.
How to Automatically Disable Vendors After Subscription Cancellation
To implement this functionality, you can use custom code to hook into subscription status changes and manage vendor capabilities accordingly. Here’s how:
1. Use WooCommerce Subscriptions Hooks
If you’re using WooCommerce Subscriptions, you can hook into subscription status changes like woocommerce_subscription_status_cancelled
.
add_action('woocommerce_subscription_status_cancelled', 'disable_dokan_vendor_on_subscription_cancel'); function disable_dokan_vendor_on_subscription_cancel($subscription_id) { // Get the subscription $subscription = wcs_get_subscription($subscription_id); // Get the vendor user ID from the subscription $vendor_user_id = $subscription->get_customer_id(); // Check if the user is a vendor if (dokan_is_user_seller($vendor_user_id)) { // Change the vendor's role to "customer" or any non-vendor role wp_update_user([ 'ID' => $vendor_user_id, 'role' => 'customer', ]); // Optionally notify the vendor wp_mail( get_userdata($vendor_user_id)->user_email, 'Your Vendor Account Has Been Disabled', 'Your subscription has been canceled, and your selling privileges have been revoked. Please renew your subscription to continue selling.' ); } }
2. Use Dokan’s Built-In Hooks
Dokan provides filters and actions to manage vendor capabilities. For example:
- Use
dokan_is_seller_enabled
to check and control if a vendor can sell. - Example:
add_filter('dokan_is_seller_enabled', 'check_vendor_subscription_status', 10, 2); function check_vendor_subscription_status($is_enabled, $vendor_user_id) { // Check if the vendor's subscription is active $has_active_subscription = check_vendor_subscription($vendor_user_id); // Replace with your own logic if (!$has_active_subscription) { return false; // Disable the vendor } return $is_enabled; } function check_vendor_subscription($vendor_user_id) { // Custom logic to verify subscription status // Return true if active, false otherwise return false; // Example: Assume subscription is inactive }
3. Plugins for Automation
If coding isn’t preferable, consider using additional plugins to bridge the gap:
- WooCommerce Subscriptions Integration: Plugins like Dokan WooCommerce Subscription Integration may add automated features for handling vendor subscriptions.
- Membership Plugins: Some membership plugins can manage user roles based on subscription status.
Steps to Implement
- Identify how subscriptions are managed on your site.
- Decide whether you want immediate disabling or a grace period.
- Use the code above or relevant plugins to implement the desired behavior.
- Test thoroughly to ensure vendors are disabled appropriately without unintended disruptions.
Let me know if you’d like help customizing the code further! ????
Guys if you will have any kind of query then feel free to comment below.
Thanks
Jassa
Recent Comments