• Resolved solojuve1897

    (@solojuve1897)


    Hi.

    I followed this guide (https://lifterlms.com/docs/add-custom-fields-lifterlms-checkout-open-registration/) and added the code to my theme functions.php. The field Company Name appeared on the checkout page. How can I now see what was inputted on that order through the admin-panel? Nothing about a Company Name appears on the specific order. I have looked in my database and the custom field isnt actually saved in the usermeta table…

    So this last part doesnt seem to work?

    function save_custom_company_name( $person_id, $data , $screen ){
    	add_user_meta( $person_id, 'llms_company_name', $data['llms_company_name'], true);
    }
    add_action( 'lifterlms_user_registered', 'save_custom_company_name', 10, 3);
Viewing 11 replies - 1 through 11 (of 11 total)
  • @solojuve1897,

    If you want to display this information you’re going to need to read on in the tutorial: https://lifterlms.com/docs/add-custom-fields-lifterlms-checkout-open-registration/#display-reporting & https://lifterlms.com/docs/add-custom-fields-lifterlms-checkout-open-registration/#display-profile-wp

    Can you post me a full snippet (via a gist or pastebin) of the actual code you’re adding so I can debug it.

    Thanks,

    Thread Starter solojuve1897

    (@solojuve1897)

    @thomasplevy

    Sorry for the late reply. Here is what I added to my functions.php file.

    https://pastebin.com/w9gKuwUw

    The code is as I said before partly working with the Company Name-field appearing on the Checkout-page. The problem is the second part. How can I see what the user entered while making that specific order?

    Thread Starter solojuve1897

    (@solojuve1897)

    Anything?

    Thread Starter solojuve1897

    (@solojuve1897)

    I really don’t understand how one can build a plugin for this purpose and then leave out something fundamental as this. There isnt a blueprint for what an academy needs to collect by its students. In Sweden we for example need to collect the National ID number. Yet there isnt an easy way to add a simple field on the checkout to collect this, which is very frustrating.

    • This reply was modified 7 years, 3 months ago by solojuve1897.

    Hey @solojuve1897.

    I really don’t understand how one can build a plugin for this purpose and then leave out something fundamental as this.

    Try building and maintaining a system with as many features and parts as LifterLMS and then you’ll understand. I neglect hundreds of features. There’s thousands of requests that will never be built. I can’t do it all. You’ll have to accept that this isn’t a feature we have and if you can’t work without it you’ll want to kindly look for another solution and accept my apologies.

    The code is as I said before partly working with the Company Name-field appearing on the Checkout-page. The problem is the second part. How can I see what the user entered while making that specific order?

    If you want to display custom information on the order screen you’ll want to use this action hook: https://github.com/gocodebox/lifterlms/blob/master/templates/admin/post-types/order-details.php#L236

    Or really any of the other hooks in that template. Something like this should work given the code you provided:

    <?php
    add_action( 'lifterlms_after_order_meta_box', function( $order ) {
    		
    	$user_id = $order->get( 'user_id' );
    	$name = get_user_meta( $user_id, 'llms_company_name', true );
    	printf( __( 'Company Name: %s', 'my-text-domain' ), $name );
    
    } );
    

    That’ll display the custom user meta field on the bottom of the order information metabox on the admin panel.

    Hope that helps,

    Thread Starter solojuve1897

    (@solojuve1897)

    Hi @thomasplevy

    Thank you for your reply. A Company Name field is now showing on the order-page. But it’s empty since the save function doesnt seem to do its job correctly…

        function save_custom_company_name( $person_id, $data , $screen ){
        	add_user_meta( $person_id, 'llms_company_name', $data['llms_company_name'], true);
        }
        add_action( 'lifterlms_user_registered', 'save_custom_company_name', 10, 3);

    As I have noted before I have looked in my database and the custom field isnt actually saved in the usermeta table.

    • This reply was modified 7 years, 3 months ago by solojuve1897.
    Thread Starter solojuve1897

    (@solojuve1897)

    I have found the problem with the code. The validation and save functions are only called if one creates an account during checkout. Never otherwise. During these conditions the value passed to the custom field is saved and is displayed in the edit order page. The reason is of course these two lines:

    lifterlms_user_registered
    lifterlms_user_registration_data

    How do I make it so that the value inputted to the custom field is connected to the specific order and not the user?

    • This reply was modified 7 years, 3 months ago by solojuve1897.
    Thread Starter solojuve1897

    (@solojuve1897)

    Its been three days now. Anything? How do I solve this mess?

    @solojuve1897

    https://gist.github.com/thomasplevy/6ef898581ad95f86bd66fe9a7bcc6415

    I have found the problem with the code. The validation and save functions are only called if one creates an account during checkout. Never otherwise. During these conditions the value passed to the custom field is saved and is displayed in the edit order page. The reason is of course these two lines:

    lifterlms_user_registered
    lifterlms_user_registration_data

    Woo, sorry about that. I updated the sample code at https://lifterlms.com/docs/add-custom-fields-lifterlms-checkout-open-registration/#add-fields to save to the usermeta table upon registration and updates (so it’ll work for both new and existing accounts).

    How do I make it so that the value inputted to the custom field is connected to the specific order and not the user?

    The example saves to the USER meta table and doesn’t exactly address saving this data to an order. You can pretty easily save it to an order instead though. I don’t have a set of APIs built out to accommodate a custom “order” field and everything in these tutorial revolves around user fields. However, you add the fields in this same method and save to the order instead with something like this:

    
    <?php
    add_action( 'lifterlms_new_pending_order', 'my_custom_order_field', 10, 2 );
    function my_custom_order_field( $order, $person ) {
       update_post_meta( $order->get( 'id' ), 'my_custom_meta_key', $_POST['my_custom_field_name'] );
    }
    

    You can then display this on the order with code like this:

    
    <?php
    add_action( 'lifterlms_after_order_meta_box', function( $order ) {
    		
    	$name = get_user_meta( $order->get( 'id' ), 'my_custom_meta_key', true );
    	printf( __( 'Company Name: %s', 'my-text-domain' ), $name );
    
    } );
    

    Hope that helps,

    Thread Starter solojuve1897

    (@solojuve1897)

    @thomasplevy

    Thank you for your help. That solved it. With a small modification:

    get_post_meta in the last function instead of get_user_meta.

    Thread Starter solojuve1897

    (@solojuve1897)

    • This reply was modified 7 years, 3 months ago by solojuve1897. Reason: Double
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add custom field order checkout’ is closed to new replies.