Okay
  Public Ticket #3368772
Catching appointment canceled to make refund
Closed

Comments

  •  10
    Acceleralia started the conversation

    As said in the title, we are trying to catch when a customer cancels an appointment to refund him what he paid. We saw that when a apointment is cancelled it makes a call to "admin-ajax.php?action=wpamelia_api&call=/bookings/cancel/id&source=cabinet-customer".

    Is there any way to catch when that is called and make woocommerce refund to the customer?

  •  1,583
    Uroš replied

    Hello,

    Thank you for reaching out to us.

    We will soon have this option available in Amelia, but at the moment, there is no such option.

    Please let me know if you have any other questions.

    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  10
    Acceleralia replied

    Hello,

    We managed to add this feature for customers. Just need to add this code to admin-ajax.php:

    if($_GET['action'] == "wpamelia_api" && $_GET['source']=="cabinet-customer"){
        global $wpdb;
        $call = explode("/",$_GET['call']);
        if($call[1]=="bookings" && $call[2]=="cancel"){
            $appointmentID = $call[3];
            $payment = $wpdb->get_results("SELECT p.customerBookingId,p.wcOrderId,p.amount FROM {$wpdb->prefix}amelia_payments p WHERE p.customerBookingId = ". $appointmentID."")[0];
            $order  = wc_get_order( $payment->wcOrderId );
            $order_items   = $order->get_items();
            $line_items = array();
            if ( $order_items ) {
                foreach( $order_items as $item_id => $item ) {
                    $item_meta  = $order->get_item_meta( $item_id );
                                $tax_data = $item_meta['_line_tax_data'];
                    $refund_tax = 0;
                            if( is_array( $tax_data[0] ) ) {
                                $refund_tax = array_map( 'wc_format_decimal', $tax_data[0] );
                            }
                            $refund_amount = wc_format_decimal( $refund_amount ) + wc_format_decimal( $item_meta['_line_total'][0] );
                            $line_items[ $item_id ] = array(                     'qty' => $item_meta['_qty'][0],                     'refund_total' => wc_format_decimal( $item_meta['_line_total'][0] ),                     'refund_tax' =>  $refund_tax );
                }
            }
            $refund = wc_create_refund( array(
                'amount'         => $payment->amount, // you can modify the amout if you want to add a tax or smth
                'reason'         => "reason here",
                'order_id'       => $payment->wcOrderId,
                'line_items'     => $line_items,
                'refund_payment' => true
            ));
        } }
  •  1,583
    Uroš replied

    Hello,

    Glad to hear that and thank you for sharing this with others. This will mean a lot to other people as well.

    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables