Adding new field to Woocommerce PDF invoice
-
Hello,
I am trying to add the “VAT ID #” field from my Dokan vendor registration form (named: VAT ID) to show upon the Woocommerce PDF invoices (under the vendor’s address). I am trying to find proper action/filter hooks to achieve it, but having a bit of a difficult time.
I am looking @ Hooks and Filters in WooCommerce PDF Invoice: https://docs.woocommerce.com/document/pdf-invoice-developer-tools/ but not sure which of these would help achieve what I am trying to do. I am not sure if this applies to me as I was told that “I need to fetch the data to the Dokan Invoice. The Dokan Invoice file dokan-invoice.php”
Would I just apply the following in my functions.php file or dokan-invoice.php?
add_filter( 'dokan_settings_form_bottom', 'extra_fields', 10, 2); function extra_fields( $current_user, $profile_info ){ $VAT ID= isset( $profile_info['VAT ID'] ) ? $profile_info['VAT ID'] : ''; ?> <div class="gregcustom dokan-form-group"> <label class="dokan-w3 dokan-control-label" for="setting_address"> <?php _e( 'VAT Number', 'dokan' ); ?> </label> <div class="dokan-w5"> <input type="text" class="dokan-form-control input-md valid" name="VAT ID" id="reg_VAT ID" value="<?php echo $VAT ID; ?>" /> </div> </div> <?php } //save the field value add_action( 'dokan_store_profile_saved', 'save_extra_fields', 15 ); function save_extra_fields( $store_id ) { $dokan_settings = dokan_get_store_info($store_id); if ( isset( $_POST['VAT ID'] ) ) { $dokan_settings['VAT ID'] = $_POST['VAT ID']; } update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings ); } // show on the store page add_action( 'dokan_store_header_info_fields', 'save_VAT ID', 10); function save_VAT ID($store_user){ $store_info = dokan_get_store_info( $store_user); ?> <?php if ( isset( $store_info['VAT ID'] ) && !empty( $store_info['VAT ID'] ) ) { ?> <i class="fa fa-globe"></i> <?php echo esc_html( $store_info['VAT ID'] ); ?> <?php } ?> <?php }
Hope someone can help.
Best,
Chris
- The topic ‘Adding new field to Woocommerce PDF invoice’ is closed to new replies.