# After members save 60 item on the database, I need monthly plan or subscription automatically canceled even if the month aren't ending

**URL:** <https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661>\
**Category:** Ask the community\
**Tags:** wix-members-area, question, code\
**Created:** [December 7, 2021, 2:59am UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661 "2021-12-07T02:59:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eulapro](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eulapro](https://forum.wixstudio.com/u/eulapro)\
**Post date:** [December 7, 2021, 2:59am UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/1 "2021-12-07T02:59:21Z")

</div>

Hi there, I have a site with a monthly payment but i need a code that member only can use what I offer 60 times then automatically plans subscription cancel, or automatically expiry, even if the month are not ending. what i offer is something that person click a button and copy to the clipboard so if you copy and click the button 60 times, plan is over, even if the month is not ending, so member needs to pay again. Thank you, is my first time on the forum. I need some help

---

<div class="post-metadata">

**Author:** ![jarod](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jarod/32/3202_2.png) [@jarod](https://forum.wixstudio.com/u/jarod)\
**Post date:** [December 7, 2021, 4:08pm UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/2 "2021-12-07T16:08:00Z")

</div>

This is what you need to do.

When a member clicks on the button, add something to the database. You can do this with the [wixData.save() api.](https://www.wix.com/velo/reference/wix-data/save)

Then in the then after the save write this -

```javascript
import wixData from 'wix-data';
import wixUsers from 'wix-users'
// ...

let toSave = {
  "title": "Mr.",
  "first_name": "John",
  "last_name": "Doe"
};

wixData.save("myCollection", toSave)
	.then( (results) => {
		let items = results.items; //see item below
		let count = items.length
		if (count >= 60) {
		
		}
	} )

```

Then inside that .then((results)) you need to get the users plans and cancel the first plan they have. [https://www.wix.com/velo/reference/wix-paid-plans/cancelorder](https://www.wix.com/velo/reference/wix-paid-plans/cancelorder)

---

<div class="post-metadata">

**Author:** ![eulapro](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eulapro](https://forum.wixstudio.com/u/eulapro)\
**Post date:** [December 8, 2021, 11:52pm UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/3 "2021-12-08T23:52:22Z")

</div>

thank you sir let me try it, will let you know

---

<div class="post-metadata">

**Author:** ![eulapro](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eulapro](https://forum.wixstudio.com/u/eulapro)\
**Post date:** [December 9, 2021, 12:19am UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/4 "2021-12-09T00:19:06Z")

</div>

Hi sir, I do not understand this part below, how I can do that Thank you:  
Then inside that .then((results)) you need to get the users plans and cancel the first plan they have.

---

<div class="post-metadata">

**Author:** ![eulapro](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eulapro](https://forum.wixstudio.com/u/eulapro)\
**Post date:** [December 9, 2021, 12:28am UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/5 "2021-12-09T00:28:24Z")

</div>

Hi sir, That is what i did, is that the right code ?

Thank you

import wixData from ‘wix-data’ ;  
import wixUsers from ‘wix-users’  
// …  
**let** toSave = {  
“title” : “Mr.” ,  
“first\_name” : “John” ,  
“last\_name” : “Doe”  
};

wixData . save ( “myCollection” , toSave )  
. then ( ( results ) =\> {  
**let** items = results . items ; //see item below  
**let** count = items . length  
**if** ( count \>= 60 ) {  
wixPaidPlans . cancelOrder (1)  
}  
} )

---

<div class="post-metadata">

**Author:** ![eulapro](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eulapro](https://forum.wixstudio.com/u/eulapro)\
**Post date:** [December 9, 2021, 12:39am UTC](https://forum.wixstudio.com/t/after-members-save-60-item-on-the-database-i-need-monthly-plan-or-subscription-automatically-canceled-even-if-the-month-arent-ending/1661/6 "2021-12-09T00:39:33Z")

</div>

Its almost the same code, is that right ? thank you  
**import** wixData **from** ‘wix-data’ ;  
**import** wixPaidPlans **from** ‘wix-paid-plans’ ;  
**import** wixUsers **from** ‘wix-users’ ;  
**let** user = wixUsers . currentUser ;

**let** toSave = {  
“title” : “Mr.” ,  
“first\_name” : “John” ,  
“last\_name” : “Doe”  
};

wixData . save ( “myCollection” , toSave )  
. then ( ( results ) =\> {  
**let** items = results . items ; //see item below  
**let** count = items . length  
**if** ( count \>= 60 ) {  
wixPaidPlans . cancelOrder ( 1 )  
}  
} )
