1

I have a property site, I have rooms as products in WooCommerce. There is an option to rent the room whether for 6 months or 12 months. I did a workaround and for 6 months the product quantity will be 1 and for 12 months the quantity will be 2.

E.g For 6 months price is 2000 (quantity 1) For 12 months price 4000(quantity 2)

Now what I want is to restrict the product (room) to be purchased only once.

Link : https://heyrooms.com/property/morden-apartment-balham-london-6/

The book now button add the product in the cart according to the time period in the drop down above.

Edit: I can't use a variable product options. Because it's not the case here.

mujuonly
  • 11,370
  • 5
  • 45
  • 75
HasaanCh
  • 23
  • 7

1 Answers1

1

I would propose a different approach to solving the problem. Why don't you create the products as variable instead of simple. You can then set the price accordingly for 6m/1y. Then just make the stock quantity as 1. You should then be good to go.

Abhishek
  • 55
  • 4
  • The main problem here is I am not directly interacting with woocommerce. I am using a property plugin ere to manage properties and I did some custom work around to purchase the properties because ere don't provide the functionality. I used quick buy plugin api to purchase by clicking on purchase button. – HasaanCh Apr 16 '20 at 19:59
  • You can have a look here https://heyrooms.com/property/morden-apartment-balham-london-6/ – HasaanCh Apr 16 '20 at 20:00
  • 1
    Are you trying to do all this from somewhere other than the site itself? Maybe I don't understand the whole scenario clearly but if a button is what you need then you can just make one and link it to the checkout url for a particular product (or variation) using the product ID. See this: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/ – Abhishek Apr 16 '20 at 20:14
  • yup that's what I am doing at the moment. i do realize now that i can use vairations with it too. But still I can't use variations now. Because my client is not comfortable with it. Can we do it like that when the purchase is made the stock drops to zero? – HasaanCh Apr 16 '20 at 20:30
  • You can add an action to `woocommerce_thankyou` hook which will find all the purchased products and then use `$product->set_stock_quantity(0)` over each product to set the qty as 0. – Abhishek Apr 17 '20 at 08:01
  • You can see this: https://stackoverflow.com/a/42533543/12675543 – Abhishek Apr 17 '20 at 08:02
  • Thank you so much I will try it and respond back immediately. – HasaanCh Apr 17 '20 at 09:49