Customer Vat Number
-
Hi All
I am trying to add custom data that is in my orders for clients that are companies that want their VAT number displayed on the invoice in the Billing section of the pdf.
I have the following code where the phone number is working but the VAT number and clients mobile number is not pulling in
Code below added in the Invoice.php when using the custom PDF
<?php if ( isset( $this->settings['_display_vat'] ) ) : ?> <div class="billing_vat">Vat: <Strong></Strong>Vat: <?php $this->billing_vat(); ?></div> <?php endif; ?> <br> <?php if ( isset( $this->settings['display_phone'] ) ) : ?> <div class="billing-phone"><Strong>P: </Strong><?php $this->billing_phone(); ?></div> <?php endif; ?> <br> <?php if ( isset( $this->settings['_display_mobile'] ) ) : ?> <div class="billing_mobile"><Strong>M: </Strong><?php $this->billing_mobile(); ?><div> <?php endif; ?> </td>The code I have I am using on the admin order side is below
add_filter( ‘woocommerce_admin_billing_fields’, ‘njengah_admin_billing_fields’ );
function njengah_admin_billing_fields( $fields ) {
$fields['vat'] = array( 'label' => __( 'Vat number', 'njengah' ), 'show' => true ); $fields['mobile'] = array( 'label' => __( 'Mobile number', 'njengah' ), 'show' => true ); return $fields; }/**
Filter to copy the Vat field from User meta fields to the Order Admin form (after clicking the dedicated button on the admin page)
****/
add_filter( 'woocommerce_found_customer_details', 'custom_found_customer_details' ); function custom_found_customer_details( $customer_data ) { $customer_data['billing_vat'] = get_user_meta( $_POST['user_id'], 'billing_vat', true ); $customer_data['billing_mobile'] = get_user_meta( $_POST['user_id'], 'billing_mobile', true ); return $customer_data; }-
This topic was modified 2 years, 8 months ago by
nevillecampher.
The page I need help with: [log in to see the link]
-
This topic was modified 2 years, 8 months ago by
-
/***************************** FRONTEND ****************************************/ /************************** Filter to add a Vat field to: - My Account - Edit Form -- Billing fields - Checkout - Edit Form - Billing Fields This function is also reordering the form fields Source: https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters ***************************/ function add_woocommerce_billing_fields($billing_fields){ //reorder woo my billing address form fields $billing_fields2['billing_first_name'] = $billing_fields['billing_first_name']; $billing_fields2['billing_last_name'] = $billing_fields['billing_last_name']; $billing_fields2['billing_company'] = $billing_fields['billing_company']; $billing_fields2['billing_vat'] = $billing_fields['billing_vat']; $billing_fields2['billing_address_1'] = $billing_fields['billing_address_1']; $billing_fields2['billing_address_2'] = $billing_fields['billing_address_2']; $billing_fields2['billing_suburb'] = $billing_fields['billing_suburb']; $billing_fields2['billing_phone'] = $billing_fields['billing_phone']; $billing_fields2['billing_mobile'] = $billing_fields['billing_mobile']; $billing_fields2['billing_vat'] = array( 'type' => 'text', 'label' => __('Vat number', 'keyelp-shop-customization' ), 'class' => array('form-row-wide'), 'required' => false, 'clear' => true ); $billing_fields2['billing_mobile'] = array( 'type' => 'text', 'label' => __('Mobile number', 'keyelp-shop-customization' ), 'class' => array('form-row-wide'), 'required' => true, 'clear' => true ); //unimos el resto de campos $merged_billing_fields = $billing_fields2 + $billing_fields; return $merged_billing_fields; } add_filter('woocommerce_billing_fields' , 'display_billing_vat_fields'); function display_billing_vat_fields($billing_fields){ $billing_fields['billing_vat'] = array( 'type' => 'text', 'label' => __('Vat number', 'woocommerce' ), 'class' => array('form-row-wide'), 'required' => false, 'clear' => true, 'priority' => 35, // To change the field location increase or decrease this value ); return $billing_fields; } add_filter('woocommerce_billing_fields' , 'display_billing_mobile_fields'); function display_billing_mobile_fields($billing_fields){ $billing_fields['billing_mobile'] = array( 'type' => 'text', 'label' => __('Mobile number', 'woocommerce' ), 'class' => array('form-row-wide'), 'required' => true, 'clear' => true, 'priority' => 35, // To change the field location increase or decrease this value ); return $billing_fields; } /*************************** ADMIN ORDER PAGE ****************************************/ /********* Filter to add Vat to the Edit Form on Order -- Admin page on Order view - Neville these to stay working on order adminb opage when edit *********/ add_filter( 'woocommerce_admin_billing_fields', 'njengah_admin_billing_fields' ); function njengah_admin_billing_fields( $fields ) { $fields['vat'] = array( 'label' => __( 'Vat number', 'njengah' ), 'show' => true ); $fields['mobile'] = array( 'label' => __( 'Mobile number', 'njengah' ), 'show' => true ); return $fields; } /**************** Filter to copy the Vat field from User meta fields to the Order Admin form (after clicking the dedicated button on the admin page) ******************/ add_filter( 'woocommerce_found_customer_details', 'custom_found_customer_details' ); function custom_found_customer_details( $customer_data ) { $customer_data['billing_vat'] = get_user_meta( $_POST['user_id'], 'billing_vat', true ); $customer_data['billing_mobile'] = get_user_meta( $_POST['user_id'], 'billing_mobile', true ); return $customer_data; }Above is the code I used to add a custom field into my Woocommerce for a Customer VAT field and Client Mobile Number.
So I need to get the info (vat and Mobile number on the PDF that is done via this code and saved in my clients order that I can insert to pull from the custom PDF file Invoice.php
-
This reply was modified 2 years, 8 months ago by
nevillecampher.
-
This reply was modified 2 years, 8 months ago by
nevillecampher.
Did you add the setting to this setting to the plugin?
$this->settings['_display_vat']If so, in what section did you add it? Could you share the code, please. It’s likely this is returning an empty string
Good Day dwpriv
Have not use the code you gave above in your post. I have a snipped that has the the code below that adds to my order in the billing details admin frontend the Vat field and the mobile field. Here is the code. It also adds in in the front end when a order is placed and the clients checks out a order on the billing details
/***************************** FRONTEND ****************************************/ /************************** Filter to add a Vat field to: - My Account - Edit Form -- Billing fields - Checkout - Edit Form - Billing Fields This function is also reordering the form fields Source: https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters ***************************/ function add_woocommerce_billing_fields($billing_fields){ //reorder woo my billing address form fields $billing_fields2['billing_first_name'] = $billing_fields['billing_first_name']; $billing_fields2['billing_last_name'] = $billing_fields['billing_last_name']; $billing_fields2['billing_company'] = $billing_fields['billing_company']; $billing_fields2['billing_vat'] = $billing_fields['billing_vat']; $billing_fields2['billing_address_1'] = $billing_fields['billing_address_1']; $billing_fields2['billing_address_2'] = $billing_fields['billing_address_2']; $billing_fields2['billing_suburb'] = $billing_fields['billing_suburb']; $billing_fields2['billing_phone'] = $billing_fields['billing_phone']; $billing_fields2['billing_mobile'] = $billing_fields['billing_mobile']; $billing_fields2['billing_vat'] = array( 'type' => 'text', 'label' => __('Vat number', 'keyelp-shop-customization' ), 'class' => array('form-row-wide'), 'required' => false, 'clear' => true ); $billing_fields2['billing_mobile'] = array( 'type' => 'text', 'label' => __('Mobile number', 'keyelp-shop-customization' ), 'class' => array('form-row-wide'), 'required' => true, 'clear' => true ); //unimos el resto de campos $merged_billing_fields = $billing_fields2 + $billing_fields; return $merged_billing_fields; } add_filter('woocommerce_billing_fields' , 'display_billing_vat_fields'); function display_billing_vat_fields($billing_fields){ $billing_fields['billing_vat'] = array( 'type' => 'text', 'label' => __('Vat number', 'woocommerce' ), 'class' => array('form-row-wide'), 'required' => false, 'clear' => true, 'priority' => 35, // To change the field location increase or decrease this value ); return $billing_fields; } add_filter('woocommerce_billing_fields' , 'display_billing_mobile_fields'); function display_billing_mobile_fields($billing_fields){ $billing_fields['billing_mobile'] = array( 'type' => 'text', 'label' => __('Mobile number', 'woocommerce' ), 'class' => array('form-row-wide'), 'required' => true, 'clear' => true, 'priority' => 35, // To change the field location increase or decrease this value ); return $billing_fields; } /*************************** ADMIN ORDER PAGE ****************************************/ /********* Filter to add Vat to the Edit Form on Order -- Admin page on Order view - Neville these to stay working on order adminb opage when edit *********/ add_filter( 'woocommerce_admin_billing_fields', 'njengah_admin_billing_fields' ); function njengah_admin_billing_fields( $fields ) { $fields['vat'] = array( 'label' => __( 'Vat number', 'njengah' ), 'show' => true ); $fields['mobile'] = array( 'label' => __( 'Mobile number', 'njengah' ), 'show' => true ); return $fields; } /**************** Filter to copy the Vat field from User meta fields to the Order Admin form (after clicking the dedicated button on the admin page) ******************/ add_filter( 'woocommerce_found_customer_details', 'custom_found_customer_details' ); function custom_found_customer_details( $customer_data ) { $customer_data['billing_vat'] = get_user_meta( $_POST['user_id'], 'billing_vat', true ); $customer_data['billing_mobile'] = get_user_meta( $_POST['user_id'], 'billing_mobile', true ); return $customer_data; }On my Child theme i have created the Custom PDF Invoices and in the invoice.php file in my child theme i have the code below. But is shows blank and does not show the Vat, but it does. The code you gave is not in my invoice.php file and even if I add it it does not show
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?> <?php do_action( 'wpo_wcpdf_before_document', $this->get_type(), $this->order ); ?> <table class="head container"> <tr> <td class="header"> <?php if ( $this->has_header_logo() ) { do_action( 'wpo_wcpdf_before_shop_logo', $this->get_type(), $this->order ); $this->header_logo(); do_action( 'wpo_wcpdf_after_shop_logo', $this->get_type(), $this->order ); } else { $this->title(); } ?> </td> <td class="shop-info"> <?php do_action( 'wpo_wcpdf_before_shop_name', $this->get_type(), $this->order ); ?> <div class="shop-name"><h3><?php $this->shop_name(); ?></h3></div> <?php do_action( 'wpo_wcpdf_after_shop_name', $this->get_type(), $this->order ); ?> <?php do_action( 'wpo_wcpdf_before_shop_address', $this->get_type(), $this->order ); ?> <div class="shop-address"><?php $this->shop_address(); ?></div> <?php do_action( 'wpo_wcpdf_after_shop_address', $this->get_type(), $this->order ); ?> </td> </tr> </table> <?php do_action( 'wpo_wcpdf_before_document_label', $this->get_type(), $this->order ); ?> <h1 class="document-type-label"> <?php if ( $this->has_header_logo() ) $this->title(); ?> </h1> <?php do_action( 'wpo_wcpdf_after_document_label', $this->get_type(), $this->order ); ?> <table class="order-data-addresses"> <tr> <td class="address billing-address"> <!-- <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> --> <?php do_action( 'wpo_wcpdf_before_billing_address', $this->get_type(), $this->order ); ?> <?php $this->billing_address(); ?> <?php do_action( 'wpo_wcpdf_after_billing_address', $this->get_type(), $this->order ); ?> <?php if ( isset( $this->settings['display_email'] ) ) : ?> <div class="billing-email"><Strong>e: </Strong><?php $this->billing_email(); ?></div> <?php endif; ?> <?php if ( isset( $this->settings['display_phone'] ) ) : ?> <div class="billing-phone"><Strong>p: </Strong><?php $this->billing_phone(); ?></div> <?php endif; ?> <br> <?php if ( isset( $this->settings['display_billing_vat'] ) ) : ?> <div class="billing_vat"><Strong>V: </Strong><?php $this->billing_vat(); ?></div> <?php endif; ?> <br> <?php if ( isset( $this->settings['display_billing_mobile'] ) ) : ?> <div class="billing_mobile"><Strong>M: </Strong><?php $this->billing_mobile(); ?><div> <?php endif; ?> </td> <td class="address shipping-address"> <?php if ( $this->show_shipping_address() ) : ?> <h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> <?php do_action( 'wpo_wcpdf_before_shipping_address', $this->get_type(), $this->order ); ?> <?php $this->shipping_address(); ?> <?php do_action( 'wpo_wcpdf_after_shipping_address', $this->get_type(), $this->order ); ?> <?php if ( isset( $this->settings['display_phone'] ) ) : ?> <div class="shipping-phone"><?php $this->shipping_phone(); ?></div> <?php endif; ?> <?php endif; ?> </td> <td class="order-data"> <table> <?php do_action( 'wpo_wcpdf_before_order_data', $this->get_type(), $this->order ); ?> <?php if ( isset( $this->settings['display_number'] ) ) : ?> <tr class="invoice-number"> <th><?php echo $this->get_number_title(); ?></th> <td><?php $this->invoice_number(); ?></td> </tr> <?php endif; ?> <?php if ( isset( $this->settings['display_date'] ) ) : ?> <tr class="invoice-date"> <th><?php echo $this->get_date_title(); ?></th> <td><?php $this->invoice_date(); ?></td> </tr> <?php endif; ?> <tr class="order-number"> <th><?php _e( 'Order Number:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> <td><?php $this->order_number(); ?></td> </tr> <tr class="order-date"> <th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> <td><?php $this->order_date(); ?></td> </tr> <?php if ( $payment_method = $this->get_payment_method() ) : ?> <tr class="payment-method"> <th><?php _e( 'Payment Method:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> <td><?php echo $payment_method; ?></td> </tr> <?php endif; ?> <?php do_action( 'wpo_wcpdf_after_order_data', $this->get_type(), $this->order ); ?> </table> </td> </tr> </table> <?php do_action( 'wpo_wcpdf_before_order_details', $this->get_type(), $this->order ); ?> <table class="order-details"> <thead> <tr> <th class="product"><?php _e( 'Product', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> <th class="quantity"><?php _e( 'Quantity', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> <th class="price"><?php _e( 'Price', 'woocommerce-pdf-invoices-packing-slips' ); ?></th> </tr> </thead> <tbody> <?php foreach ( $this->get_order_items() as $item_id => $item ) : ?> <tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', 'item-'.$item_id, esc_attr( $this->get_type() ), $this->order, $item_id ); ?>"> <td class="product"> <?php $description_label = __( 'Description', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?> <span class="item-name"><?php echo $item['name']; ?></span> <?php do_action( 'wpo_wcpdf_before_item_meta', $this->get_type(), $item, $this->order ); ?> <span class="item-meta"><?php echo $item['meta']; ?></span> <dl class="meta"> <?php $description_label = __( 'SKU', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?> <?php if ( ! empty( $item['sku'] ) ) : ?><dt class="sku"><?php _e( 'SKU:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="sku"><?php echo esc_attr( $item['sku'] ); ?></dd><?php endif; ?> <?php if ( ! empty( $item['weight'] ) ) : ?><dt class="weight"><?php _e( 'Weight:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="weight"><?php echo esc_attr( $item['weight'] ); ?><?php echo esc_attr( get_option( 'woocommerce_weight_unit' ) ); ?></dd><?php endif; ?> </dl> <?php do_action( 'wpo_wcpdf_after_item_meta', $this->get_type(), $item, $this->order ); ?> </td> <td class="quantity"><?php echo $item['quantity']; ?></td> <td class="price"><?php echo $item['order_price']; ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr class="no-borders"> <td class="no-borders"> <div class="document-notes"> <?php do_action( 'wpo_wcpdf_before_document_notes', $this->get_type(), $this->order ); ?> <?php if ( $this->get_document_notes() ) : ?> <h3><?php _e( 'Notes', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> <?php $this->document_notes(); ?> <?php endif; ?> <?php do_action( 'wpo_wcpdf_after_document_notes', $this->get_type(), $this->order ); ?> </div> <div class="customer-notes"> <?php do_action( 'wpo_wcpdf_before_customer_notes', $this->get_type(), $this->order ); ?> <?php if ( $this->get_shipping_notes() ) : ?> <h3><?php _e( 'Customer Notes', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> <?php $this->shipping_notes(); ?> <?php endif; ?> <?php do_action( 'wpo_wcpdf_after_customer_notes', $this->get_type(), $this->order ); ?> </div> </td> <td class="no-borders" colspan="2"> <table class="totals"> <tfoot> <?php foreach ( $this->get_woocommerce_totals() as $key => $total ) : ?> <tr class="<?php echo esc_attr( $key ); ?>"> <th class="description"><?php echo $total['label']; ?></th> <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td> </tr> <?php endforeach; ?> </tfoot> </table> </td> </tr> </tfoot> </table> <div class="bottom-spacer"></div> <?php do_action( 'wpo_wcpdf_after_order_details', $this->get_type(), $this->order ); ?> <?php if ( $this->get_footer() ) : ?> <div id="footer"> <!-- hook available: wpo_wcpdf_before_footer --> <?php $this->footer(); ?> <!-- hook available: wpo_wcpdf_after_footer --> </div><!-- #letter-footer --> <?php endif; ?> <?php do_action( 'wpo_wcpdf_after_document', $this->get_type(), $this->order ); ?>isset( $this->settings['display_billing_vat'] )This line is trying to see if the VAT billing setting is enable in our settings, not WooCommerce’s settings. However we don’t have a setting like that in our plugin and I’m not seeing in the code where you’re adding this setting. So your if statement will always return false, which means the field won’t show.
If your billing_vat is saved to the order data, you use this guide here to show it.
Since we haven’t heard from you in a while, we will mark this topic as resolved. Feel free to reopen it if you still more help.
-
This reply was modified 2 years, 8 months ago by
The topic ‘Customer Vat Number’ is closed to new replies.