Okay
  Public Ticket #2928347
Using custom fields in checkout
Closed

Comments

  • Anil started the conversation

    Hello, 

    we have defined custom fields for our event bookings and have a woocommerce integration for payments. 

    Our goal was to have the custom fields like street, zip and city populated directly into the Woocommerce fields so the user doesn't have to re-enter them. 

    We managed to do that by finding the necessary function in the plugin's PHP file "WooCommerceService.php". 

    We added the custom fields to the function "checkoutGetValue" (see screenshot). 

    My question is if we could write the function in a different place so that it is not lost during an update? It would be great if someone from your development team could help us with this.

    I made this ticket public because I think this could be very useful for other customers. 

    Many greetings
    Anil


  •  2,572
    Aleksandar replied

    Hey Anil

    Thanks for sharing this with everyone. I believe this would be a great addition for Amelia, to add as an option, so the ticket will be forwarded to our developers for review.

    At the moment, there's no way to prevent the data from being overwritten with the update, but I hope our developers will be able to include something similar in one of our future updates!

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    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

  •  2,572
    Aleksandar replied

    Hi again Anil

    We'll add this in the next update, but for the moment, you can add this code before the next update is released, so even though it's going to be overwritten with the update, it'll be overwritten with the same data:

    self::$checkout_info = apply_filters(
                                'amelia_checkout_data',
                                [
                                    'billing_first_name' => $wc_item[self::AMELIA]['bookings'][0]['customer']['firstName'],
                                    'billing_last_name'  => $wc_item[self::AMELIA]['bookings'][0]['customer']['lastName'],
                                    'billing_email'      => $wc_item[self::AMELIA]['bookings'][0]['customer']['email'],
                                    'billing_phone'      => $wc_item[self::AMELIA]['bookings'][0]['customer']['phone'],
                                ],
                                self::$container,
                                $wc_key
                            );
    

    Then, you can pull what you need in the filter method:

    function amelia_checkout_data_callback($data1, $container, $key) {
        $customFields = wc()->cart->get_cart()[$key]['ameliabooking']['bookings'][0]['customFields'];
        return $data1;
    }
    add_filter('amelia_checkout_data', 'amelia_checkout_data_callback', 10, 3);
    

    I hope that helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    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

  • Anil replied

    Hello Aleksandar,

    that's fantastic. Thank you so much for taking care of it!

    Kind regards
    Anil


  • [deleted] replied

    You are most welcomesmile.png

    If there is anything else we can assist you with please don't hesitate to open a new ticket.

    Have a wonderful day! 

  • Anil replied

    Hello Alexsandar,


    You had written me once that you were going to add the feature in the next update. Has that been added yet? Now that we want to update, I would like to know how we can link the fields to WooCommerce now.

    Thank you and kind regards
    Anil

  •  2,572
    Aleksandar replied

    Hey Anil

    There's been a misunderstanding. We do plan something like this to be developed in the future, but when I mentioned that "we'll add this in the next update" I was referring to the actual functionality, not the setting within Amelia that would automatically apply custom fields to WooCommerce.

    So, you need to apply the filter we previously sent (if you haven't already):

    function amelia_checkout_data_callback($data1, $container, $key) {
        $customFields = wc()->cart->get_cart()[$key]['ameliabooking']['bookings'][0]['customFields'];
        return $data1;
    }
    add_filter('amelia_checkout_data', 'amelia_checkout_data_callback', 10, 3);

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    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

  • Anil replied

    Hi Alexsandar,


    Thank you for the answer! Ok I think I have understood now how you mean that. The filter was built into the code that can be accessed..

     In the code below is the current state of the fields we have added. We still have the old version of Amelia on it and would like to update now.

    self::$checkout_info = [
                                'billing_first_name' => $wc_item[self::AMELIA]['bookings'][0]['customer']['firstName'],
                                'billing_last_name'  => $wc_item[self::AMELIA]['bookings'][0]['customer']['lastName'],
                                'billing_email'      => $wc_item[self::AMELIA]['bookings'][0]['customer']['email'],
                                'billing_company'    => $wc_item[self::AMELIA]['bookings'][0]['customFields']['18']['value'],
                                'billing_phone'      => $wc_item[self::AMELIA]['bookings'][0]['customFields']['16']['value'],
                                'billing_address_1'  => $wc_item[self::AMELIA]['bookings'][0]['customFields']['13']['value'],
                                'billing_address_2'  => $wc_item[self::AMELIA]['dateTimeValues'][0]['start'],
                                'billing_postcode'   => $wc_item[self::AMELIA]['bookings'][0]['customFields']['14']['value'],
                                'billing_city'       => $wc_item[self::AMELIA]['bookings'][0]['customFields']['15']['value']
                            ];
                            break;

    Since we are unfortunately not professionals, could you kindly send us some sample code on how to include the custom fields in the filter? Preferably an example where you add multiple fields. That would be really helpful for us.

    Would it be right like that?

    function amelia_checkout_data_callback($data1, $container, $key) {
        $customFields = wc()->cart->get_cart()[$key]['ameliabooking']['bookings'][0]['customFields'];
        'billing_company'    => $wc_item[self::AMELIA]['bookings'][0]['customFields']['18']['value'],
        'billing_phone'      => $wc_item[self::AMELIA]['bookings'][0]['customFields']['16']['value'],
        'billing_address_1'  => $wc_item[self::AMELIA]['bookings'][0]['customFields']['13']['value'],
        'billing_address_2'  => $wc_item[self::AMELIA]['dateTimeValues'][0]['start'],
        'billing_postcode'   => $wc_item[self::AMELIA]['bookings'][0]['customFields']['14']['value'],
        'billing_city'       => $wc_item[self::AMELIA]['bookings'][0]['customFields']['15']['value']
        return $data1;
    }
    add_filter('amelia_checkout_data', 'amelia_checkout_data_callback', 10, 3);
    

    Many thanks and best regards
    Anil

  •  2,572
    Aleksandar replied

    Hey Anil

    This is how to do it:

    function amelia_checkout_data_callback($defaultData, $container, $key)
    {
        $allData = wc()->cart->get_cart()[$key]['ameliabooking'];     return array_merge(
            $defaultData,
            [
                'billing_company'    => $allData['bookings'][0]['customFields']['18']['value'],
                'billing_phone'      => $allData['bookings'][0]['customFields']['16']['value'],
                'billing_address_1'  => $allData['bookings'][0]['customFields']['13']['value'],
                'billing_address_2'  => $allData[0]['start'],
                'billing_postcode'   => $allData['bookings'][0]['customFields']['14']['value'],
                'billing_city'       => $allData['bookings'][0]['customFields']['15']['value'],
            ]
        );
    } add_filter('amelia_checkout_data', 'amelia_checkout_data_callback', 10, 3);

    In the end, the result will be what's added in the Filter, and default values: first_name, last_name, email, phone.

    If you need some further assistance, please feel free to reach out to us.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    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