• Hello

    I add the custom field “username_field” to the checkout and saving into order metadata with the following code:

    <?php
    
    add_action( 'woocommerce_before_checkout_billing_form', 'add_username_field' );
    
    function add_username_field( $cart ) {
        if (! function_exists( 'woocommerce_form_field' ) ) {
            return false;
        }
    
        ?>
        <div id="my_plugin">
            <?php
            woocommerce_form_field(
                'username_field',
                array(
                    'type'        => 'text',
                    'class'       => array(),
                    'label'       => __( 'Username', 'myplugin' ),
                    'placeholder' => __( 'A valid username', 'myplugin' ),
                    'required'    => true,
                ),
                $cart->get_value( 'username_field' )
            );
            ?>
        </div>
        <?php
    
        return true;
    }
    
    add_action( 'wt_woocommerce_checkout_order_created', 'save_username_to_order', 10, 2 );
    
    function save_username_to_order( $order, $checkout_post ) {
        if ( empty( $order ) ) {
            return;
        }
    
        $id = method_exists($order, 'get_id') ? $order->get_id() : $order->id;
    
        if ( ! isset( $checkout_post['username_field'] ) || empty( $checkout_post['username_field'] ) ) {
            return;
        }
    
        $user_name = sanitize_text_field( $checkout_post['username_field'] );
        update_post_meta( $id, 'username_field', $user_name );
    }

    When someone use the smart button to pay with credit card one of three things happens:
    1. The custom field is saved correctly
    2. The custom field is not being saved
    3. The custom field is saved into billing phone

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Rubén Chavarría

    (@rubenicos)

    After some investigation I obtained this information about the cases:

    1. The custom field is saved correctly
    The user is registered in the shop page and is not the first purchase he made.

    2. The custom field is not being saved
    The user is registered in the shop page and is the first purchase he made.

    3. The custom field is saved into billing phone
    The user is not registered.

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @rubenicos,

    Greetings from WebToffee support.

    We are sorry for the inconvenience caused. We will look into the matter by replicating the issue on our side and get back to you soon.

    In the meantime, please share the version number of the PayPal Express Checkout plugin you are using and your WooCommerce System status report (WooCommerce -> Status -> Get system status report).

    Thread Starter Rubén Chavarría

    (@rubenicos)

    I’m using the version 1.8.2 (upgraded today from 1.8.1)

    Status report: pastebin.com/raw/KfJUic9H

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @rubenicos,

    Thank you for sharing the information. We were not able to replicate the issue on our side.

    Could you please share the URL of a staging site after keeping the payments in sandbox mode? This will help us understand the issue better.

    Thread Starter Rubén Chavarría

    (@rubenicos)

    After some testing I found that the WooCommerce session obtained by the Payment Gateway Plugin for PayPal WooCommerce plugin is not the current session, instead it is obtaining the session that was saved previously.

    That is why in the first purchase with a credit card using the smart button there is no post_data on WC_Session.

    While in subsequent purchases, if a different username_field is entered, the one entered in the previous purchase is taken instead of the current one.

    So, is it a mistake from my site’s configuration or is it required to add a different way to get the current WooCommerce session?

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @rubenicos,

    Thank you for the follow up.

    We have checked the scenario on our site but couldn’t replicate it. To help us better understand the issue, please share the logs of the orders where you have noticed this issue, from the WooCommerce > Status > Logs page.

    Thread Starter Rubén Chavarría

    (@rubenicos)

    A few days ago I updated the WooCommerce version to 8.4 and the problem persists.
    Here are some logs from the same customer (I censored any personal information):

    First order log (the username is not saved): pastebin.com/raw/UuCfqZ6Y
    Second order log (The username is saved using the one entered in the first order): pastebin.com/raw/fTnz4hVZ

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @rubenicos,

    We have gone through all of your data and requirements. Smart Buttons are awesome for checkout speed, but they don’t capture custom fields always.

    If adding a custom field is crucial, we have two alternate options for you (both keep checkout smooth, just with extra address verification):

    1. Switch to standard PayPal integration: Works seamlessly with Smart Buttons, just deselect pages from the “Show Smart button on” field in the plugin settings to make the default Proceed to Paypal button appear.
    2. Enable Address Override: This keeps your custom field data and prevents checkout addresses from being changed at the PayPal end.

      Let us know if you need any further assistance.
    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @rubenicos,


    This thread has been inactive for a bit, so we are going to mark it as Resolved now. Please feel free to open a new thread or follow-up if you have any further questions or still need help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom fields not saved’ is closed to new replies.