Appointments Products not removing as per setting

Hi,

I have pending appointments set to remove after 30 minutes (my default setting in Appointments+). But they're not removing. I noticed it this morning when I still had an appointment in my shopping cart that I'd put in my basket last night

Kind Regards
Kieran

  • Adam Czajczyk

    Hello Kieran!

    It's trying to charge me twice. It should just remove from my cart should it not?

    The MarketPress is not removing items from cart that way and I'd say it's rather standard for most of the shopping carts. This is not the Appointments+ issue but rather the way store works. The "cart cookie" is valid for a month and unless user clears browser's cookies manually it expires a month after last update (meaning last item added to the cart).

    The solution here would be to change cookie expiration period but after reviewing MarketPress code I see it wouldn't be possible without changing code in plugin's core which is not a recommended way to go.

    Also to update this I have the "Disable Pending Appointmets after" set to 30 mins. However I've noticed it takes approx 40 mins to move from Pending to Remove.

    I think this is related mostly to how WP Cron works. It's not precise enough and some (sometimes even 5-10 minutes) fluctuations occur. Most likely switching WordPress to use real server Cron could help here but I admin that I haven't tried this in relation to this issue.

    Best regards,
    Adam

  • Kieran

    Hi Adam,

    I dont understand. It's standard practice for an item to remove from your cart after x minutes isn't it? Certainly is on other websites I've been on. I think it has to act this way for an Appoinments system to avoid double booking. I'd like to change the core marketpress code to 30 minutes if possible

    What would happen if I had the Appointment in my cart for say 24 hours but someone else had already booked the appointment in the mean times. Would it push through anyway and make me double booked?

    I can live with the WP Cron issue thats fine thanks for the explanation

    Kind Regards
    Kieran

  • Adam Czajczyk

    Hello Kieran!

    It's standard practice for an item to remove from your cart after x minutes isn't it?

    Personally, I don't think I ever spent enough time shopping online to be able to find out after how long items got removed from the cart. I believe though that this may be different with different e-commerce solutions. However, I agree it would be great if you could simply decide how long items should be kept in a shopping cart. Currently though I can provide you with a solution that sets "fixed" expiry timeout of 30 minutes.

    To apply it to your site please follow these steps:

    - download an attached .zip file and extract it to your local drive
    - access your WP install via FTP
    - upload "class-mp-cart.php" file from an extracted .zip archive to the

    /wp-content/plugins/marketpress/includes/common/

    folder, overwriting existing file of the same name.

    Once this is done make sure that you cleared your browser's cookies and test it, please. On my test setup it seems to be working fine and when I refresh the page past 30 minutes after most recent item has been added (or most recent change to the cart has been made such as e.g. change of amount of items) entire content of the cart is gone.

    Let me know if that works for you please!

    Please also note that this solution includes a change in plugins code and it will not survive any update of the plugin so it will have to be re-applied then. The change is quite simple though:

    in a /wp-content/plugins/marketpress/includes/common/class-mp-cart.php file this line (around line #2441)

    $expire = strtotime( '+1 month' );

    has been changed to this one

    $expire = strtotime( '+30 minutes' );

    Best regards,
    Adam

  • Kieran

    Hi Adam

    I've put the new class-mp-cart into my site but it's not working unfortunately. Is this part of code correct?

    $expire = strtotime( '+5 minutes' );
    		if ( empty( $this->_items ) ) {
    			if ( $cart_cookie = mp_get_cookie_value( $this->_cookie_id ) ) {
    				$expire = strtotime( '-1 month' );
    			} else {
    				return;
    			}
    		}

    Is the -1 month bit correct?

    Hopefully you can provide more insight. Basically if I stay on the checkout page the appointment moves to completed and I still get an order status page and order confirmation email which looks very strange.

    Kind Regards
    Kieran

  • Adam Czajczyk

    Hello Kieran!

    Yes, that part of code looks right and the "-1 month" bit is correct. I must say I'm not quite sure why it's not working for you so I'd like to take a look. Unfortunately, once I accessed your site (both as a visitor and as an admin user using support access) I was taken to the "Undergoing Site Upgrades" front-page. Could I actually make use of the site being logged in? I'd like to test that behavior.

    the appointment moves to completed and I still get an order status page and order confirmation email which looks very strange.

    Could you please explain it in a bit more detailed way? I must say that I'm slightly confused and not sure what do you mean.

    Kind Regards
    Adam

  • Kieran

    Hi Adam

    I've just taken the front page down. Support access is granted and just direct to mysite.com/bookings and you can make some test bookings. Use the Jing Massage product to see what I mean.

    I've uploaded the code as "+5 minutes" for testing. After 5 minutes of waiting if you look in the back end the Appointment moves from pending to completed (rather than removed) and you can still complete the order by clicking on submit order. Take the appointment to the checkout page and wait 10 mins and test?

    Panos had another idea to fix this on this thread but neither option is working

    https://premium.wpmudev.org/forums/topic/time-out-problem-at-checkout-with-appointments-and-marketpress

    Your code didn't work with some other code I have also. I have some code from Panos which enables me to click on Remove when I want to Remove an Appointment from my shopping cart. It's great and much needed.

    See Here. https://premium.wpmudev.org/forums/topic/remove-an-appoinment-from-shopping-cart

    It moves Appointments from Pending to Removed. Unfortunately when I run your code and click on remove after say 10 mins the Appointment has probably timed out so when you click remove the screen hangs and I just get the loading circle. It might be the same with Pano's code too I've not tested it all out. Just know it's not working at the min

    Let me know if you require FTP access.

    Kind Regards
    Kieran

  • Adam Czajczyk

    Hello Kieran!

    I re-read both threads (this one that the one with Paonos's solution) and I got a bit confused. I think we're still mixing two separate issues here:

    1. Automatically moving appointments from "pending" to "removed" status
    2. Removing appointments from product cart after some time

    Adding appointment to the cart - unless user went further, through checkout - shouldn't make appointment "pending". It's like adding any other plugin to the shopping cart: it's not sold until user goes to checkout.

    This is handled by Appointments settings. Initially you got that set up to 30 minutes I think and you can set this to any period you wish. However this doesn't affect MarketPress shoppoing cart and shopping cart doesn't affect Appointments appointments list.

    In other words: moving appointment from "pending" to "removed" won't remove anything from any cart and removing appointment from shopping cart won't move any appointment from "pending" to "removed".

    Appointments added as "pending" must have been "checked out" by customer, they just weren't confirmed yet. There shouldn't be any need for any additional code to handle this: if user doesn't confirm an appointment it gets moved to "removed" automatically after set amount of time.

    My code was about to affect shopping cart and only a shopping cart. All it does is it sets shopping cart cookie expiration time. It's not - as shopping cart is not - connected to the "Appointments" pending/removed list.

    The workflow is like this:

    - user adds appointment to the cart
    - for Appointments+ plugin that appointment, let's say, "doesn't exist"
    - user doesn't checkout within that 5 minutes that were set with my code
    - appointment gets removed from shopping cart
    - no booking slot has ever been blocked and no appointment would show up in "pending" list

    or alternative workflow

    - user adds appointment to the cart
    - user does checkout before these 5 minutes (set with my code) pass
    - booking slot is blocked and appointment is both removed from shopping cart and added to "pending" list in Appointments+ plugin

    Now there are two follow-up scenarios for this last case (and only this one):
    a) user confirms an appointment and it gets moved from "pending" to "confirmed"
    b) user doesn't confirm an appointment withing 10 minutes set in Appointments+ settings and appointment gets moved from "pending" to "confirmed" and booking slot is freed up.

    Could you please test all this on your site again having these scenarios in mind? I'd like to make sure that we're on the same side here before we go any further

    Best regards,
    Adam

  • Kieran

    Hi adam, panos

    Thanks for the detailed reply I’ll try and answer best I can! Basically I guess all I’m after is that when someone books an Appointment and takes a long time to book it does the following

    Times out properly so they don’t hog an appointment which others might want to book. I think allowing someone 60 minutes to check out is enough. If they have it in their basket longer than that I want it to time out and be available for others to book
    Some of my customers do seem to be taking for ever to book. They work in an office environment so get distracted easily. I can’t have it sat in their cart blocking the time out for others to book. I want it to be clear when they have taken >60 mins that when they click confirm, the appointment has timed out and they need to book again.

    But what is happening is that the appointment has timed out. It’s been moved to removed due to the setting in Appointments+. But it’s still in Marketpress I guess? So the customer is clicking confirm on the final page and they are getting an order email. But no Appointment confirmation email. The appointment is sat in removed (because it’s timed out)
    Is that clear the issue we need to fix?

    Adding appointment to the cart - unless user went further, through checkout - shouldn't make appointment "pending". It's like adding any other plugin to the shopping cart: it's not sold until user goes to checkout

    As soon as you click on the confirm appointment button the Appointment goes to “pending” in the back end whilst you progress through MarketPress checkout. This means it’s unavailable for anyone else to pick. As soon as you click confirm it’s in your shopping cart and the Appointment is marked as “pending”. You can check this by booking an appointment on my site.

    This is handled by Appointments settings. Initially you got that set up to 30 minutes I think and you can set this to any period you wish. However, this doesn't affect MarketPress shopping cart and shopping cart doesn't affect Appointments appointments list. 
    
    In other words: moving appointment from "pending" to "removed" won't remove anything from any cart and removing appointment from shopping cart won't move any appointment from "pending" to "removed".

    Then this is the issue we need to fix. I believe Panos has done so for me on the other thread. But perhaps it’s not dealing with the time out issue. Only when someone clicks remove on shopping cart page.

    Appointments added as "pending" must have been "checked out" by customer, they just weren't confirmed yet.

    As soon as you’re on the checkout page they are marked as pending. So my customers are not completing the checkout but the appointment is “pending”

    There shouldn't be any need for any additional code to handle this: if user doesn't confirm an appointment it gets moved to "removed" automatically after set amount of time.

    I’m particularly talking about the situation where they have confirmed the appointment but taken a long time to go through checkout. Let’s say after 60 mins the appointment is moved to removed but my customer is still sat on the final checkout page. As a customer I’ve gone on my lunch and then come back. I put my payment details in then clicked submit. The order goes through! But it shouldn’t it should be timed out. The customer gets an order confirmation email but no appointments email and the order is sat in removed. Marketpress and Appointments aren’t talking to each other here?? How do we fix this?

    b) user doesn't confirm an appointment within 10 minutes set in Appointments+ settings and appointment gets moved from "pending" to "confirmed" and booking slot is freed up.

    If the user doesn’t complete the appointment I wouldn’t want it to go to confirm I’d want it to go into removed? Would that now mean they get a confirmation email?

    Apologies I struggled to follow the workflow on the last part of your message but maybe my reply helps us move forward and what the best way might be. I’ve copied in Panos too so hopefully he sees his

    Kind Regards
    Kieran

  • Milan

    Hello Kieran

    I hope you are well today and won't mind me chiming here.

    I can understand what you are saying here, and clear solution of this issue would be setting up same expiry time limit for MarketPress cart and Appointments. Currently, appointment's expiry time is set to 60 minutes where cart cookie expiry time is set to 1 month. So even if appointment is in cart, after 60 minutes pass, user won't be able to get the slot he/she selected as it would be removed due to appointments settings.

    So best way to resolved this is to set

    #1) Expiry minutes in appointments settings to month ( It can let user manipulate your resources/slots )
    #2) Setting up cart cookie to 60 minute ( as you have selected 60 minutes as expiry limit in appointments )

    Please note here that this solution is not full proof as Appointment's expiry depends on cron and MarketPress cart depends on cookie to store respective information, but it could be possible solution.

    Hope you find this useful. Please let us know if you need help with anything else.

    Best Regards,
    Milan