Git Product home page Git Product logo

woocommerce-subscriptions-restrict-product's Introduction

WooCommerce Subscriptions Restrict Product

Restricts subscription products to a certain number of total active (unended) subscriptions on a site.

Use case: store owner wants products and subscriptions to have a one-to-one relationship, i.e. each product should only be subscribed to once. For example, subscription product is a child to be sponsored, and only one subscriber should be sponsoring that child at a time.

This plugin creates and maintains a list of products that have unended subscriptions associated with them, then makes these products unpurchasable from front end to make sure that the subscription product can only be subscribed to a certain number of times. It doesn't change ability to check out with product, so that customer can pay for failed order through cart, and manual renewals are unaffected.

Note: This plugin is designed to work independently of the WooCommerce inventory system, and so inventory should be disabled for all subscription products, or you may have problems with customers not being able to pay for failed renewal orders manually.

Installation

To install:

  1. Download the latest version of the plugin here
  2. Go to Plugins > Add New > Upload administration screen on your WordPress site
  3. Select the ZIP file you just downloaded
  4. Click Install Now
  5. Click Activate

How-to

Set Product Restriction

There are two ways to set a product restriction, either storewide or on a product level. Setting a product level restriction is more specific and will override the storewide default. If you set either to '0' or leave them empty, they are considered not set.

Storewide Restriction

You can set a default storewide restriction which will apply to all subscription products by going to WooCommerce -> settings -> Subscriptions (tab) -> Product Restriction

Admin settings

Product-level Restriction

You can also set a product restriction for a specific product by editing the product, and clicking on the 'Advanced Options' tab in the Product Data metabox. This will set the product restriction on a product level for simple and variable subscription products. That means that the restriction applies no matter which variation of a variable product is subscribed to.

  • To activate the product-level restriction, you must click the "Activate product-level restriction" checkbox.
  • If "Activate product-level restriction" checkbox is checked, but the restriction quantity is blank, then no restriction will be applied to this product, even if there is a systemwide default set elsewhere.

Product settings

Renewals and Switching

Renewals and Switches are taken into account when checking if a purchase should be restricted.

Renewals

Automatic renewals are not restricted at all, and should process normally. Similarly, manual renewals will still allow the product to be purchased/renewed through the cart.

Subscription Switching

Switching is accounted for when checking restrictions. When switching between simple subscription products, the checks still occur as normal. When switching between variations of the same product, the restrictions are ignored, allowing the switch to occur.

Visibility

When displaying a product in the catalog or archive pages, this plugin will hide the product if it is restricted, and if the 'Out of stock visibility' option is checked in WooCommerce settings -> products -> inventory tab.

Warning Messages

There is currently no way to customize the warning message presented when a restriction is encountered. Additionally, when product variations are deemed not purchasable, the default WooCommerce alert box is triggered, which is not descriptive of why.

For this reason, we recommend you add in some descriptive text to your product description indicating that it is restricted, and why.

Additional Notes

  • Restrictions don't apply retroactively, only to future purchases. In other words, any given purchase is checked against the current restriction and current number of active site-wide subscriptions. No already-existing subscriptions will be cancelled or suspended if you change the restriction number. Future purchases will be checked against subscriptions that existed before the plugin was activated, however.
  • Deactivating the plugin will stop the restriction checks, and will delete the cache. However, the restriction option values (set in the WooCommerce settings tab or product options) will stay in place in case you choose to reactivate the plugin in the future.

Troubleshooting

To view the current cache for troubleshooting purposes, navigate to the 'plugins' page and click the 'view cache' option. View cache

Updates

To keep the plugin up-to-date, use the GitHub Updater.

Reporting Issues

If you find a problem or would like to request this plugin be extended, please open a new Issue.

woocommerce-subscriptions-restrict-product's People

Contributors

lcmry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woocommerce-subscriptions-restrict-product's Issues

Add UI

Add UI to specify number of subscriptions-per-product. Probably best as a per-product setting, in the advanced tab. (check out subscription limiting setting for reference)

Testing and Review

Checklist for testing:

  • Cache is created correctly on plugin activation
  • Cache is deleted on plugin deactivation
  • Cache is updated correctly when subscription statuses change
  • Cache is updated correctly when subscription is purchased
  • Unrestricted subscription products can be purchased normally
  • Simple subscription is not visible in shop and not purchasable, when restricted
  • Variable subscription is not visible in shop and variations are not purchasable, when product is restricted
  • Not allowing multiple quantities from making it through the cart if it bumps above the restricted number
  • Place product in cart/checkout, then restrict it and try to checkout
  • Manual Renewal should still work for a restricted product
  • Paying for a failed renewal order should still work for a restricted product
  • Switching between grouped simple products should prevent purchase if the one being switched to is restricted
  • Switching between variations of a variable product should bypass the restriction, since restriction is set on a product level
  • Resubscription should not work if the product became restricted since the sub was cancelled or expired
  • Restriction can be set sitewide in Subs settings and also from product page
  • Product-level restriction setting will override storewide setting

Add visibility toggle

Create settings toggle that will affect whether the 'visibility' of a product is affected by this plugin.

Some customers want to still have their products be visible in the catalog, etc, even if they are not purchasable.

Edit: one possible solution to this might be to tie into the default WooCommerce "Out of Stock Visibility" toggle.

Cache will not delete after deactivating plugin

I am having an issue where one of my customers cannot purchase a subscription. It set to have one active subscription at a time but there are no active subscriptions currently for the specific product.

I see the product listed in the cache but I can't clear the cache when deactivating the plugin. How can I clear the cache?

Allow for n-to-1 relationship

This is coming from a request to have a 4-to-1 relationship between subs and product. To work this into the plugin, there would need to be an entry in the cache for each time a subscription was added, so this line would need to be removed: https://github.com/Prospress/woocommerce-subscriptions-one-to-one/blob/master/wcs-one-to-one.php#L93

Also, instead of checking if the value is in the cache, we'd need to check for a specific number of times it's in there, here: https://github.com/Prospress/woocommerce-subscriptions-one-to-one/blob/master/wcs-one-to-one.php#L122

Doesn't prevent purchase of more than the number specified

For example, if your product is restricted to "1" subscription, you could still add a quantity of "2" to the cart and be able to check out with that, since we aren't validating the cart. We are only making the item not purchasable if there already exist that many subscriptions for it when visiting the product page.

I can't think of any way to address this, so it's possible that this plugin will only work if "limit to one" is set, to prevent this.

Refresh cache after sub is created in admin area

Subscriptions created in the admin area won't add to the cache, only ones purchased the normal way through the checkout process.

Perhaps the cache can be refreshed after manual creation, or there's a hook I'm missing where I can add it to the cache.

Single product page

Product hidden from shop page - but should there also be a warning when viewing single product page directly?

Perhaps a deactivation of 'add to cart' button?

Allow for customization/translation of warning messages

This is a feature request that I predict will happen. I can add it in at a later date if it becomes necessary.

Would need to customize:

  • Single product warning
  • Cart warning
  • Default WooCommerce "is not purchasable" alert box

Could set as a storewide setting in the options, or on a product level.

Another option might be to make it translatable, so that people could use Say What? to change the text themselves. That would have the added benefit of making it translatable for international users as well.

Not restricting at all.

Hi there.

I have installed it and set the limit to 6 on a product with 6 active subscriptions and it is not doing anything.

Basically you can still add the product to the cart. and If I change the quantity available to 0 or make the product Out of stock renewals do not work as they can not be added to the cart if the product is out of stock.

I have read the note about not restricting retroactively. Does this mean if I have 8 active subscriptions before I install the plugin it wont start restricting until 8 more are booked?

Thanks

Limit subscriptions but enable up/downgrades

Hi there,

First of all, thank you for the plugin. :) Secondly, I have a store with 3 different types of subscriptions each with a monthly and yearly option. Because these are relatively different products we have them separately (and not as variable).

Is there an option that limits the active subscriptions per user to one but lets the user buy another subscription instead of their current one? In this case, users could upgrade or downgrade but have only one subscription at any given time.

Thank you very much for your help in advance.

Best regards,
Gabor

Add Cache display page

It might be nice for admins to see the current running list of products with active subscriptions. This could be as a JS hidden area on the subscriptions options tab, or a separate page.

Actually i see is not working anymore

Hi, thanks in advance for share this enhance for this plugin.

Actually im working on a subscription website and i want to limit to 1 purchase per client on all website. I tried other snippets but i cant renewal my subscriptions. I see your plugin respect that but currenly i cant see this is working because let me buy another subscriptions, so i think the core core change. _unanfortully im not good at all with code so i write this here.

Hope you can update this because is so usefull.
King Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.