• Resolved offpeakdesign

    (@offpeakdesign)


    I have Learndash integrated with Woocommerce and Tin Canny reporting. In the Woocommerce registration form, I have a custom form field called “My Aspire Number” and wish for that data to appear in either the Learndash user report or the tin canny user report. Right now, it only sends the data to the admin via email.

    The custom form field was added as a snippet:

    // Frontend: Display the custom billing fields (in checkout and my account)
    add_filter( 'woocommerce_billing_fields' ,'add_custom_billing_fields', 20, 1 );
    function add_custom_billing_fields( $fields ) {
    
        $fields['billing_aspire'] = array(
            'label' => __( 'My Aspire Number', 'woocommerce' ),
            'placeholder'   => _x('Aspire Number', 'placeholder', 'woocommerce'),
            'required'  => false,
            'class'     => array('form-row-wide'),
            'clear'     => true
        );
    
        return $fields;
    }
    
    // Save the custom billing fields (once order is placed)
    add_action( 'woocommerce_checkout_create_order', 'save_custom_billingt_fields', 20, 2 );
    function save_custom_billingt_fields( $order, $data ) {
        if ( isset( $_POST['billing_aspire'] ) && ! empty( $_POST['billing_aspire'] ) ) {
            $order->update_meta_data('_billing_aspire', sanitize_text_field( $_POST['billing_aspire'] ) );
            update_user_meta( $order->get_customer_id(), 'billing_aspire', sanitize_text_field( $_POST['billing_aspire'] ) );
        }
     
    }
    
    // Display in emails
    add_action( 'woocommerce_email_after_order_table', 'display_new_checkout_fields_in_emails', 20, 4 );
    function display_new_checkout_fields_in_emails( $order, $sent_to_admin, $plain_text, $email ) {
        if ( get_post_meta( $order->get_id(), 
    	'_billing_aspire', true ) ) 
    	  echo '<p><strong>Aspire Number:</strong> ' 
    	  . get_post_meta( $order->get_id(), '_billing_aspire', true ) . '</p>';
      
    }
    
    // Backend: Display editable custom billing fields
    add_filter( 'woocommerce_admin_billing_fields' , 'order_admin_custom_fields' );
    function order_admin_custom_fields( $fields ) {
        global $the_order;
    
        $fields['billing_aspire'] = array(
            'label' => __( 'Aspire Number', 'woocommerce' ),
            'show'  => true,
            'wrapper_class' => 'form-field-wide',
            'style' => '',
        );
    
        return $fields;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom form field reporting’ is closed to new replies.