Manual Payment Appointments not auto confirming after MarketPress Update

Hi

My appointments used to auto confirm in the previous version of marketpress with the following code copied into the manual-payments.php file

function order_confirmation($order) {
global $appointments ;
if ( isset( $_COOKIE["wpmudev_appointments"] ) ):
$apps = unserialize( stripslashes( $_COOKIE["wpmudev_appointments"] ) );
$apps = array_values(array_filter(array_map('intval', $apps)));
foreach ($apps as $id) {
$a = $appointments->get_app($id);
if('pending' === $a->status){
$appointments->change_status('confirmed',$id);
$appointments->send_confirmation($id);
}
}
endif;
}

Will this work if I do it again and if so where do I copy it too? I used to copy it after

function order_confirmation($order) {

but that bit is not there anymore in the manual-payments.php file

Kind Regards
Kieran

  • Michael Bissett

    Hey @Kieran, Michael here! :slight_smile:

    After doing a bit of poking here, I inserted the code here:

    global $appointments;
    		    if ( isset( $_COOKIE["wpmudev_appointments"] ) ) {
    				$apps = unserialize( stripslashes( $_COOKIE["wpmudev_appointments"] ) );
    				$apps = array_values(array_filter(array_map('intval', $apps)));
    					foreach ($apps as $id) {
    						$a = $appointments->get_app($id);
    							if('pending' === $a->status){
    								$appointments->change_status('confirmed',$id);
    								$appointments->send_confirmation($id);
    							}
    					}
    			}

    On line 79 of:

    /marketpress/includes/common/payment-gateways/manual-payments.php

    And found that to auto-confirm my manual payment orders. :slight_smile:

    Could you give that a try, and letting me know if that works for you too?|

    Please advise,
    Michael

  • Panos

    Hi Kieran ,

    Of what I understand you need appointments to autoconfirm when a new order is made using manual payments.

    If this is the case, you can try adding the following snipet in a mu-plugin or your functions.php:

    if( ! class_exists( 'WPMUDEV_App_Auto_Confirm_Manual_Paid_Apps' ) ){
    
    	class WPMUDEV_App_Auto_Confirm_Manual_Paid_Apps{
    		private static $_instance = null;
    
    		public static function get_instance() {
    			if ( is_null( self::$_instance ) ) {
    				self::$_instance = new WPMUDEV_App_Auto_Confirm_Manual_Paid_Apps();
    			}
    			return self::$_instance;
    		}
    
    		private function __construct(){
    
    			add_action( 'mp_order/new_order', array( $this, 'maybe_autoconf' ), 10 );
    
    		}
    
    		public function maybe_autoconf( $order ){
    
    			$payment_method = mp_get_post_value( 'payment_method', '' );
    
    			if( $payment_method != 'manual_payments' ){
    				return;
    			}
    
    			$cart_info = is_object( $order ) && is_callable( array( $order, 'get_cart' ) )
    				? $order->get_cart()->get_items()
    				: ( isset( $order->mp_cart_info ) ? $order->mp_cart_info : array() )
    			;
    
    			if( !is_object( $cart_info ) || epmty( $cart_info ) ){
    				global $mp_cart;
    				$cart_info = $mp_cart->get_items();
    			}
    
    			$variation_type = MP_Product::get_variations_post_type();
    			$appointment_ids = array();
    
    			if ( is_array( $cart_info ) && count( $cart_info ) ) {
    
    				foreach ( $cart_info as $cart_id => $count ) {
    					$variation = get_post( $cart_id );
    					if ( ! empty( $variation->post_type ) && $variation_type === $variation->post_type && $this->_is_app_mp_page( $variation->post_parent ) ) {
    						$app_id = MP_Product::get_variation_meta( $variation->ID, 'name' );
    						if ( is_numeric( $app_id ) ) {
    							$appointment_ids[] = $app_id;
    						}
    					}
    				}
    			}
    
    			foreach ($appointment_ids as $aid) {
    
    				if ( ! appointments_update_appointment_status( $aid, 'paid' ) ) {
    					continue;
    				}
    				do_action('app_mp_order_paid', $aid, $order);
    			}
    
    		}
    
    		private function _is_app_mp_page ( $product ) {
    
    			$product = get_post($product);
    			$result = is_object( $product ) && strpos( $product->post_content, '[app_' ) !== false
    				? true
    				: false
    			;
    			// Maybe required for templates
    			return apply_filters( 'app_is_mp_page', $result, $product );
    
    		}
    
    	}
    
    	add_action( 'plugins_loaded', function(){
            $GLOBALS['WPMUDEV_App_Auto_Confirm_Manual_Paid_Apps'] = WPMUDEV_App_Auto_Confirm_Manual_Paid_Apps::get_instance();
        }, 10 );
    
    }

    Please let us know if this is what you were looking for :slight_smile:

    Cheers!