Customer's company name / reorder address

This topic contains 19 replies, has 4 voices, and was last updated by  Kiran 5 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #2545

    Martin Steimann
    Free User
    Post count: 262

    Hello,

    I am trying to customize the input fields of an invoice before checking out.

    What I would like to achieve:

    Provide a company entry field for the customer, and reorder the address on the final invoice, so it looks something like this:

    From:
    Demo Provider Company
    My Demoname
    Demostreet 1
    12345 Democity

    To:
    Demo Customer Company
    His Demoname
    Demostreet 2
    12345 Democity

    The „From“-part works almost perfectly already. But I do not want to show my Email-Address.

    1. How can I hide it?

    The „To“-part is where I struggle. It looks like this (please also see attached screenshot):

    His Name
    Demostreet 2
    Democity, Demostate, Democountry 12345
    E-Mail:demo@demo.xyz

    I tried to set the State/Province as non mandatory (please note screenshot) but on checkout it alerts me that this field is required. Problem is: in Germany there are some cities like Hamburg, which are a state a well, which looks somewhat strange on the invoice’s „To“-address. Although I tried to force a company field, it doesn’t show up as an entry option. I’ve read in another query that Company and VAT fields can be shown on the address entry site, but I need a company-name field ONLY.

    So I would like to:

    2: be able leave the city/state field blank, or at least not shown in the final invoice.

    3: be given a customer name entry field

    4: Show the customer’s company name in the final invoice

    5: show the Zip-Code ahead of the city name, as it ist required for invoices in Germany.

    6: hide the customer’s Email-Adress as well

    OMG, this sounds like a lot of demands! And there ist still one more (really hope you don’t mind).

    7. Open a new window if a customer clicks on print invoice right after the payment confirmation. Because otherwise the displayed invoice might be the only page that is open on his browser and the only way to return to his profile is the browser’s back button.

    Thank you for reading this lengthy report!

    #2549

    Martin Steimann
    Free User
    Post count: 262
    This reply has been marked as private.
    #2552

    Paolo
    Site Admin
    Post count: 31206

    Hi martin,

    I’ve flagged your request for a developer.

    Thank you

    #2559

    Kiran
    Moderator
    Post count: 7069

    Hello Martin,

    – The „From“-part works almost perfectly already. But I do not want to show my Email-Address.
    1. How can I hide it?

    Add following css snippet at Invoicing > Settings > Misc > Custom CSS > Invoice Template CSS.

    
    
    .wpinv-print .wpinv-from-address .email_from {
    	display: none !important;
    }

    2: be able leave the city/state field blank, or at least not shown in the final invoice.

    We have fixed this, now city/state fields can be optional. Here is patch: https://github.com/AyeCode/invoicing/pull/190/commits/5a5e2b12e3bc8324da76ea99f3964a608af0e316

    3: be given a customer name entry field

    Can you clarify this, because there are already fields to enter first name/last name?

    4: Show the customer’s company name in the final invoice

    If company name saved in checkout form then it will be displayed on invoice.

    5: show the Zip-Code ahead of the city name, as it ist required for invoices in Germany.
    6: hide the customer’s Email-Adress as well

    Add following PHP snippet to implement this.

    
    
    function wpi_snippet_190122_display_to_address( $output, $invoice ) {
        $billing_details = $invoice->get_user_info();
        $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
        $output .= '<div class="wrapper col-xs-10">';
        
        ob_start();
        do_action( 'wpinv_display_to_address_top', $invoice );
        $output .= ob_get_clean();
        
        $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
        if ( $company = $billing_details['company'] ) {
            $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
        }
        $address_row = '';
        if ( $address = $billing_details['address'] ) {
            $address_row .= wpautop( wp_kses_post( $address ) );
        }
        
        $address_fields = array();
        if ( !empty( $billing_details['city'] ) ) {
            $address_fields[] = $billing_details['city'];
        }
        
        $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
        if ( !empty( $billing_details['state'] ) ) {
            $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
        }
    
        if ( !empty( $billing_country ) ) {
            $address_fields[] = wpinv_country_name( $billing_country );
        }
    
        if ( !empty( $address_fields ) ) {
            $address_fields = implode( ", ", $address_fields );
            
            if ( !empty( $billing_details['zip'] ) ) {
                $address_fields = $billing_details['zip'] . ', ' . $address_fields;
            }
    
            $address_row .= wpautop( wp_kses_post( $address_fields ) );
        }
        
        if ( $address_row ) {
            $output .= '<div class="address">' . $address_row . '</div>';
        }
    
        if ( $phone = $invoice->get_phone() ) {
            $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
        }
    	// Hide email form To address.
        //if ( $email = $invoice->get_email() ) {
        //    $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
        //}
    
        ob_start();
        do_action( 'wpinv_display_to_address_bottom', $invoice );
        $output .= ob_get_clean();
        
        $output .= '</div>';
    
    	return $output;
    }
    add_filter( 'wpinv_display_to_address', 'wpi_snippet_190122_display_to_address', 10, 2 );

    7. Open a new window if a customer clicks on print invoice right after the payment confirmation. Because otherwise the displayed invoice might be the only page that is open on his browser and the only way to return to his profile is the browser’s back button.

    Please provide url or screenshot, on which page you want this update?

    If you want to disable VAT feature and want to show company fields then try the snippet provided here: https://wpinvoicing.com/support/topic/collect-company-info-even-when-not-required/#post-1077

    Invoice page using templating system, so you can also do customization via template. You can copy template file \invoicing\templates\wpinv-invoice-print.php to your THEME OR CHILD THEME DIRECTORY/invoicing/wpinv-invoice-print.php

    Let us know.

    Thanks,
    Kiran

    #2566

    Martin Steimann
    Free User
    Post count: 262

    Thank you for your reply,Kiran!

    1. now the „from“ Email is hidden, great!

    2. I have implemented the patch and it works, thank you!

    3. Sorry, I meant Customer’s company name field (yes, the name field is already there), so that 4. the company name gets displayed on the invoice’s address first, followed by the name.

    If company name saved in checkout form then it will be displayed on invoice.

    Do you mean the Checkmark in the invoice settings, which says „Force the display of the company name when paying“? I have checked this but there is no company name field in the checkout form.

    5/6. in which function php do these lines of code go? includes/wpinv-general-functions.php?

    If you want to disable VAT feature and want to show company fields then try the snippet provided here: https://wpinvoicing.com/support/topic/collect-company-info-even-when-not-required/#post-1077

    Maybe this solves number 4. In which function php would I add the code mentioned in the link?

    7. Its the payment confirmation page (please note attached screenshot). If you click on the button, it would be helpful if this action would open a new window.

    Regards,
    Martin

    #2569

    Kiran
    Moderator
    Post count: 7069

    Hello,

    5/6. in which function php do these lines of code go? includes/wpinv-general-functions.php?

    PHP code snippets can be executed via PHP Snippet plugin or putting in theme/child-theme functions.php file.
    Here is one of plugin that you can use https://wordpress.org/plugins/code-snippets/

    Do you mean the Checkmark in the invoice settings, which says „Force the display of the company name when paying“?

    Company field is used to work with tax/vat system. So if tax feature is disabled on site then company field no longer will be visible. But via “Force the display of the company name when paying” setting you can make it appear even tax setting disabled.

    Maybe this solves number 4. In which function php would I add the code mentioned in the link?

    If EU Vat is disabled then this snippet will display company field on checkout form.

    7. Its the payment confirmation page (please note attached screenshot). If you click on the button, it would be helpful if this action would open a new window.

    Use following code snippet to open those links in new window.

    
    
    /**
     * Open invoice links in new window.
     */
    function wpi_snippet_190122_invoice_receipt_actions( $actions, $invoice ) {
    	if ( ! empty( $actions ) ) {
    		foreach ( $actions as $i => $action ) {
    			$actions[ $i ]['attrs'] = 'target="_blank"';
    		}
    	}
    	return $actions;
    }
    add_filter( 'wpinv_invoice_receipt_actions', 'wpi_snippet_190122_invoice_receipt_actions', 10, 2 );

    Thanks,
    Kiran

    #2573

    Martin Steimann
    Free User
    Post count: 262

    Thanks for your patience. We’re almost there.

    Open invoice in new window works!

    I have implemented all your recommenced code (e.g. Change Address Order and Display Company Name Field.)

    Company Name Address field now shows up in the checkout form, as well as the VAT field. Still not sure if I have set all the right checkmarks in the invoicing plugin’s EU VAT SETTINGS. I made a screenshot and attached it (screenshot 1, sorry, only with german translation). Maybe it helps if I explain what I would like to achieve:

    My customers live only in Germany. So there is no need for my customers to enter their VAT number. If someone tries to add a listing to my directory from another EU country, I will let them know by Email that they cannot add their listing.

    With your provided code, both Company Name and VAT Number fields are displayed in the checkout form (see screenshot 2). Even if not mandatory – if a customer enters his VAT number „accidentally“, it gets displayed on his invoice with a title, which does not make sense (see screenshot 3) Of course I could translate it to something which makes sense, but I think the best solution for me would be that the VAT input field is not shown at all within invoice details of the checkout page. Only the much needed Company Name should be shown. Is this possible?

    Regarding the address order – its almost perfect now. But I still need to have the Company’s name on top, followed the customer’s name. And I am almost sure I can figure out how to remove the colon after the ZIP code. You surly do, don’t you? The Country Name is not needed at all, and if displayed (it is right now, because I cannot leave the country field empty in the invoice details) should go into one extra line beneath it (but maybe that is too demanding). So the final result would be:

    Grogor’s Demo Company
    Gregor Mustermann
    Demostreet 1
    20251 Democity
    Deutschland

    Or

    Grogor’s Demo Company
    Gregor Mustermann
    Demostreet 1
    20251 Democity, Deutschland

    Again, I really appreciate how you and your team are sorting out all of my special requests!

    Regards, Martin

    #2591

    Kiran
    Moderator
    Post count: 7069

    Hello,

    I think the best solution for me would be that the VAT input field is not shown at all within invoice details of the checkout page. Only the much needed Company Name should be shown. Is this possible?

    You can adjust snippet and remove/hide vat field. Or you can use this snippet to add custom fields to checkout & invoice. https://gist.github.com/kprajapatii/9ccf874ef416aca692351f237367f9f7
    This snippet asks phone & company description from checkout page and displays on invoice page.

    You surly do, don’t you? The Country Name is not needed at all, and if displayed (it is right now, because I cannot leave the country field empty in the invoice details) should go into one extra line beneath it (but maybe that is too demanding)

    Remove country related code from function wpi_snippet_190122_display_to_address() which is snippet at https://wpinvoicing.com/support/topic/customers-company-name-reorder-address/#post-2559

    To move company name up
    change:

    
    
    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
        if ( $company = $billing_details['company'] ) {
            $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
        }

    to:

    
    
    if ( $company = $billing_details['company'] ) {
    		$output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
    	}
    	$output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';

    Let us know.

    Kiran

    #2595

    Martin Steimann
    Free User
    Post count: 262

    Thank you for your reply, Kiran.

    The invoice „To“ address order is now perfect!

    The field for customers’s company name still gets only displayed by adding code to the functions.php of the child theme.
    (Please note this code near the end)
    /**
    * show company name input field.
    */

    
    
    /**
     * Open invoice links in new window.
     */
    function wpi_snippet_190122_invoice_receipt_actions( $actions, $invoice ) {
    	if ( ! empty( $actions ) ) {
    		foreach ( $actions as $i => $action ) {
    			$actions[ $i ]['attrs'] = 'target="_blank"';
    		}
    	}
    	return $actions;
    }
    add_filter( 'wpinv_invoice_receipt_actions', 'wpi_snippet_190122_invoice_receipt_actions', 10, 2 );
    
    /**
     * Change address order on invoice.
     */
    
    function wpi_snippet_190122_display_to_address( $output, $invoice ) {
        $billing_details = $invoice->get_user_info();
        $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
        $output .= '<div class="wrapper col-xs-10">';
        
        ob_start();
        do_action( 'wpinv_display_to_address_top', $invoice );
        $output .= ob_get_clean();
        
        if ( $company = $billing_details['company'] ) {
    		$output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
    	}
    	$output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
        $address_row = '';
        if ( $address = $billing_details['address'] ) {
            $address_row .= wpautop( wp_kses_post( $address ) );
        }
        
        $address_fields = array();
        if ( !empty( $billing_details['city'] ) ) {
            $address_fields[] = $billing_details['city'];
        }
    
        if ( !empty( $address_fields ) ) {
            $address_fields = implode( ", ", $address_fields );
            
            if ( !empty( $billing_details['zip'] ) ) {
                $address_fields = $billing_details['zip'] . ' ' . $address_fields;
            }
    
            $address_row .= wpautop( wp_kses_post( $address_fields ) );
        }
        
        if ( $address_row ) {
            $output .= '<div class="address">' . $address_row . '</div>';
        }
    
        if ( $phone = $invoice->get_phone() ) {
            $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
        }
    	// Hide email form To address.
        //if ( $email = $invoice->get_email() ) {
        //    $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
        //}
    
        ob_start();
        do_action( 'wpinv_display_to_address_bottom', $invoice );
        $output .= ob_get_clean();
        
        $output .= '</div>';
    
    	return $output;
    }
    add_filter( 'wpinv_display_to_address', 'wpi_snippet_190122_display_to_address', 10, 2 );
    
    /**
     * show company name input field.
     */
     
     function _wpi_custom_checkout_company_info_display_fields( $billing_details ) {
        global $wpinv_euvat;
    
        if ( ! empty( $wpinv_euvat ) && ! $wpinv_euvat->allow_vat_rules() ) {
            $tax_label = __( $wpinv_euvat->get_vat_name(), 'invoicing' );
    
            $company_mandatory = false; // Company name mandatory?
            $vat_number_mandatory = false; // Vat number mandatory?
            ?>
            <p class="wpi-cart-field wpi-col2 wpi-colf">
                <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?><?php if ( $company_mandatory ) { echo '<span class="wpi-required">*</span>'; } ?></label>
                <?php
                echo wpinv_html_text( array(
                        'id'            => 'wpinv_company_custom',
                        'name'          => 'wpinv_company_custom',
                        'value'         => $billing_details['company'],
                        'class'         => 'wpi-input form-control',
                        'placeholder'   => __( 'Company name', 'invoicing' ),
                        'required'      => $company_mandatory,
                    ) );
                ?>
            </p>
            <p class="wpi-cart-field wpi-col2 wpi-coll">
                <label for="wpinv_vat_number_custom" class="wpi-label"><?php echo wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ); ?><?php if ( $vat_number_mandatory ) { echo '<span class="wpi-required">*</span>'; } ?></label>
                <?php
                echo wpinv_html_text( array(
                        'id'            => 'wpinv_vat_number_custom',
                        'name'          => 'wpinv_vat_number_custom',
                        'value'         => $billing_details['vat_number'],
                        'class'         => 'wpi-input form-control',
                        'placeholder'   => wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ),
                        'required'      => $vat_number_mandatory,
                    ) );
                ?>
            </p>
            <?php
        }
    }
    add_action( 'wpinv_checkout_billing_fields_first', '_wpi_custom_checkout_company_info_display_fields', 10, 1 ); // Display at top
    //add_action( 'wpinv_checkout_billing_fields_last', '_wpi_custom_checkout_company_info_display_fields', 10, 1 ); // Display at bottom
    
    function _wpi_custom_checkout_company_info_set_fields() {
        global $wpinv_euvat;
    
        if ( isset( $_POST['wpinv_company_custom'] ) && isset( $_POST['wpinv_vat_number_custom'] ) && ! empty( $wpinv_euvat ) && ! $wpinv_euvat->allow_vat_rules() ) {
            $_POST['wpinv_company'] = $_POST['wpinv_company_custom'];
            $_POST['wpinv_vat_number'] = $_POST['wpinv_vat_number_custom'];
        }
    }
    add_action( 'wpinv_pre_process_checkout', '_wpi_custom_checkout_company_info_set_fields', 10 );
    
    function _wpi_custom_checkout_company_info_save_fields( $post, $user_info, $valid_data ) {
        global $wpinv_euvat, $wpi_cart;
    
        if ( isset( $post['wpinv_company_custom'] ) && isset( $post['wpinv_vat_number_custom'] ) && ! empty( $wpinv_euvat ) && ! empty( $wpi_cart ) && ! $wpinv_euvat->allow_vat_rules() ) {
            $wpi_cart->set( 'company', $post['wpinv_company_custom'] );
            $wpi_cart->set( 'vat_number', $post['wpinv_vat_number_custom'] );
            $wpi_cart->save();
        }
    }
    add_action( 'wpinv_checkout_before_gateway', '_wpi_custom_checkout_company_info_save_fields', 10, 3 );

    If I cut out this Change address order on invoice-snippet, then the company name field is not displayed even if „force company name visibility“ is checked at the invoicing settings.

    Can you please advise me (unfortunately I have no coding skills at all) wich part of the „_wpi_custom_checkout_company_info_display_fields“ I have to remove, so that the VAT number field is hidden? My only concern would be, that in hiding the VAT field the „first name“ and „second name“ fields would end up not being in the same row. (see attached screenshot)

    I really wish you and your team could add the same functionality for setting up a invoice checkout form as in a GeoDirectory Listing form, where the admin can set up the required form fields and rearrange the order manually. This would give the admin unlimited possibilities to create a checkout form which suits the invoicing demands of the country he lives in. Maybe this could be implemented in a future version (or chargeable add-on) of this really helpful plugin?

    Regards,
    Martin

    #2621

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #2623

    Martin Steimann
    Free User
    Post count: 262
    This reply has been marked as private.
    #2627

    Alex Rollin
    Moderator
    Post count: 27815

    We recommend you use the code snippets plugin for snippets
    https://wpgeodirectory.com/docs/useful-plugins/#snippets

    #2786

    Martin Steimann
    Free User
    Post count: 262
    This reply has been marked as private.
    #2789

    Alex Rollin
    Moderator
    Post count: 27815

    Please provide FTP and we will take a look.

    #2794

    Martin Steimann
    Free User
    Post count: 262
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 20 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket