WCMp PDF Invoice Hooks and Filters

And a very good news for people who want to take WCMp PDF Invoice a level further, we have readied a few hooks and filters for you to customize.

Where to add the Snippets?

Snippets are to be added to the functions.php file in your theme. If you have a custom theme developed for your site then simply paste the code into the functions.php and you’re good to go. However, if you are using a pre-built theme, it will be safe to create a child theme first and then paste the code snippet to its functions.php, thereby, preventing your modifications from being lost with a theme update.

Learn to add a child theme to your site from https://codex.wordpress.org/Child_Themes.

The following section gives a brief on the previous settings and it’s corresponding snippet.

Add more settings to PDF Invoice

Action to add more PDF Invoice Settings for vendor

// Add extra field in vendor dashboard pdf invoice settings - this example shows adding a GST Number Field for vendors to add in theirs.
add_action( 'after_wcmp_pdf_invoices_settings_field', 'add_extra_fields_in_vendor_pdf_settings', 10, 2 );
function add_extra_fields_in_vendor_pdf_settings( $vendor_id, $settings ) {
    $gst_no = isset($settings['vendor_gst_number']) ? $settings['vendor_gst_number'] : ''; ?>
    <div class="form-group">
        <label class="control-label col-sm-3"> <?php _e('GST Number', 'wcmp-pdf_invoices'); ?></label>
        <div class="col-md-6 col-sm-9">
            <input type="text" id="vendor_gst_number" name="vendor_gst_number" class="form-control regular-text" value="<?php echo $gst_no; ?>" >


Filter to save the value added by the vendor

// Save the extra field in vendor dashboard pdf invoice settings - this example shows saving the GST Number Field for vendors added in the previous step.
add_filter( 'before_wcmp_pdf_invoices_save_settings', 'save_extra_fields_in_vendor_pdf_settings', 10, 3 );
function save_extra_fields_in_vendor_pdf_settings( $before_save_data, $post_data, $vendor ) {
    $before_save_data['vendor_gst_number'] = isset($post_data['vendor_gst_number']) ? sanitize_text_field($post_data['vendor_gst_number']) : '';
    return $before_save_data;


Filter to show the value added by the vendor on the invoice

// Show the extra field in vendor's pdf invoice - this example shows the GST Number Field in the invoice added previously.
add_filter( 'after_wcmp_pdf_invoice_order_invoice_details', 'show_extra_fields_in_vendor_pdf_template' );
function show_extra_fields_in_vendor_pdf_template($args){
   $settings = isset($args['settings']) ? $args['settings'] : array();
   if($settings['vendor_gst_number'] && !empty($settings['vendor_gst_number'])){ ?>
   <tr> <td> <?php _e('GST Number:', 'wcmp-pdf_invoices'); ?> </td><td><?php echo $settings['vendor_gst_number']; ?></td></td> </tr>
   <?php }


P.S. Have more ideas to share or facing a hard to explain issue? Our quick support will definitely help you in the right direction… that’s a word you can trust.

Having trouble or need further help! Reach us!!
Last updated on August 22, 2019
Found any error... Submit your feedback
Was this helpful?

Buy all Marketplace addons together!!

Check Slashed Price