Adding SKU and Customer Phone number to the invoice.

WCMp PDF Invoice

Adding SKU and Customer Phone number to the invoice. Open

Viewing 9 reply threads
  • Author
    Posts
    • #108680
      Nathaniel George
      Participant

      Please guide me on adding the sku of products and the phone number of the customer (below address) in the pdf invoice

    • #108694

      Hello Nathaniel,

      Thank you for reaching out to us.

      You can add the SKU of the products from the admin dashboard as you can see here (https://prnt.sc/vaoggd) and from the vendor dashboard as you can see here (https://prnt.sc/vaolff).

      Regarding the other part, please refer to this thread link (https://wc-marketplace.com/support-forum/topic/display-the-customers-telephone-number-on-the-invoice-and-the-delivery-note/) which will guide you accordingly.

      Kindly let us know if you need any further assistance.

    • #108765
      Nathaniel George
      Participant

      I wanted those sku in the PDF invoice as a column, how to implement that. Please guide on it

    • #108841
      abhirup
      Moderator

      Hi,
      using below hook you can add the column and column data before product column
      Add table header – do_action(‘before_wcmp_pdf_invoice_template_items_table_header’, $hook_data);
      Add table data – do_action(‘before_wcmp_pdf_invoice_template_items_table_data’, $hook_data);

      Add the column and column data after total column

      Add table header – do_action(‘after_wcmp_pdf_invoice_template_items_table_header’, $hook_data);
      Add table data – do_action(‘after_wcmp_pdf_invoice_template_items_table_data’, $hook_data);

      if you want the sku column after the product column then you have to override the template.
      If you using second template of pdf then you have to override the template file —
      Override templates/wcmp_pdf_invoice_second_template.php template by copying it to yourtheme/wcmp-pdf-invoices/wcmp_pdf_invoice_second_template.php
      check the line no 77
      <?php $WCMp_PDF_Invoices->utils->get_order_details_table_as_html($hook_data); ?>
      this line of code showing the table.
      remove line no 77 and add below code

      <div class="product-detail-wrap <?php echo $hook_data["template"]; ?>">
          <table class="product-price-table">
              <thead>
                  <tr>
                      <?php do_action('before_wcmp_pdf_invoice_template_items_table_header', $hook_data); ?>
                      <th width="50%"><?php _e('Item', 'wcmp-pdf_invoices'); ?></th>
                      <th align="center"><?php _e('Price', 'wcmp-pdf_invoices'); ?></th>
                      <th align="center"><?php _e('Quantity', 'wcmp-pdf_invoices'); ?></th>
                      <th align="right"><?php _e('Total', 'wcmp-pdf_invoices'); ?></th>
                      <?php do_action('after_wcmp_pdf_invoice_template_items_table_header', $hook_data); ?>
                  </tr>
              </thead>
              <tbody>
                  <?php $items = $WCMp_PDF_Invoices->utils->get_order_items($hook_data["order"]->get_id(),$hook_data["user_id"]); 
                  if( sizeof( $items ) > 0 ) : 
                  foreach( $items as $item_id => $item ) : $item_obj = $hook_data["order"]->get_item($item_id); ?>
                      <tr>
                          <?php do_action('before_wcmp_pdf_invoice_template_items_table_data', $hook_data); ?>
                          <td class="product">
                              <span class="item-name"><?php echo esc_html( $item_obj->get_name() ); ?></span>
                              <?php do_action( 'before_wcmp_pdf_invoice_template_item_meta', $hook_data["pdf_type"], $item, $hook_data["order"] ); ?>
                              <ul class="meta">
                              <?php $show_order_itemmeta = $WCMp_PDF_Invoices->utils->show_order_itemmeta();
                              if ( $meta_data = $item_obj->get_formatted_meta_data( '' ) ) :
                                  foreach ( $meta_data as $meta_id => $meta ) :
                                      if ( !in_array( $meta->key, $show_order_itemmeta, true ) ) {
                                          continue;
                                      }
                                      if($meta->key == '_vendor_id'){
                                          $meta->display_key = __('Sold by', 'wcmp-pdf_invoices');
                                          $vendor = get_wcmp_vendor($meta->value);
                                          $meta->display_value = $vendor->page_title;
                                      }
                              ?>
                              <li class="item-meta"><span><?php echo wp_kses_post( $meta->display_key ); ?>:</span> <span><?php echo wp_kses_post( force_balance_tags( $meta->display_value ) ); ?></span></li>
                              <?php endforeach; endif; ?>
                              </ul>
                              <?php do_action( 'after_wcmp_pdf_invoice_template_item_meta', $hook_data["pdf_type"], $item, $hook_data["order"] ); ?>
                          </td>
                          <td class="price" align="center"><?php echo wc_price( $hook_data["order"]->get_item_total( $item_obj, false, true ), array( 'currency' => $hook_data["order"]->get_currency() ) ); ?></td>
                          <td class="qunatity" align="center"><?php echo "&times; " . esc_html( $item_obj->get_quantity() ); ?></td>
                          <td class="total" align="right"><?php echo wc_price( $item_obj->get_total(), array( 'currency' => $hook_data["order"]->get_currency() ) ); ?></td>
                          <?php do_action('after_wcmp_pdf_invoice_template_items_table_data', $hook_data); ?>
                      </tr>
                  <?php endforeach; endif; ?>
              </tbody>
              <tfoot align="right">
                  <?php $order_item_totals = $WCMp_PDF_Invoices->utils->get_order_item_totals($hook_data["order"]->get_id(), $hook_data["user_id"], $hook_data["user_type"]);
                  if($order_item_totals) : 
                      foreach ($order_item_totals as $key => $total) { ?>
                          <tr>
                              <td colspan="2"></td>
                              <td><?php echo $total['label'];?></td>
                              <td><?php echo $total['value'];?></td>
                          </tr>
                      <?php }
                  endif;
                  ?>
              </tfoot>
          </table>
      </div>
      Copy

      then add table header and data where you want.

      Regards,

    • #108873
      Nathaniel George
      Participant

      Let me explain what I did:

      • Commented line 77
      • Added the code instead

      But it didn’t work. What else should I have added? By the way, I also use a child theme, should I override it by adding it to the child theme’s folder or parent theme’s folder?

    • #108906
      abhirup
      Moderator

      Hi,
      First off all select Second template as a default PDF template from admin panel. Then create a file on your child theme on
      yourtheme/wcmp-pdf-invoices/wcmp_pdf_invoice_second_template.php
      After that add below code in this wcmp_pdf_invoice_second_template.php file.

      <?php
      /*
       * The template for displaying vendor dashboard
       * Override this template by copying it to yourtheme/wcmp-pdf-invoices/wcmp_pdf_invoice_second_template.php
       *
       * @author  WC Marketplace
       * @package     WCMp PDF Invoices/Templates
       * @version     2.0.3
       */
      
      global $WCMp_PDF_Invoices;
      $invoice_data = $WCMp_PDF_Invoices->utils->get_invoice($order->get_id(),$user_id);
      $hook_data = array(
          'order' => $order,
          'template' => $template,
          'pdf_type' => $pdf_type,
          'user_id' => $user_id, 
          'user_type' => $user_type,
          'settings' => $settings,
      );
      ?>
      <!-- invoice2 start -->
       
      <div class="invoice2">
          <?php do_action( 'before_wcmp_pdf_invoice_template', $hook_data ); ?>
          <table cellpadding="0" cellspacing="0" class="invoice-detail">
              <tr>
                  <td width="45%">
                      <?php echo $WCMp_PDF_Invoices->utils->header_logo($user_id) ?>
                      <?php do_action('before_wcmp_pdf_invoice_to_address_details', $hook_data); 
                      if($user_type == 'customer'){
                          ?>
                          <p class="invoice-text"><strong><?php _e('Sold By:', 'wcmp-pdf_invoices'); ?> <?php echo $WCMp_PDF_Invoices->utils->company_name($user_id, 'vendor', $order) ?></strong></p>
                          <p><?php echo $WCMp_PDF_Invoices->utils->invoice_to_address('vendor', $user_id, ', ');?></p><br/>
                          <p class="invoice-text"><strong><?php _e('Invoice to:', 'wcmp-pdf_invoices'); ?> <?php echo $WCMp_PDF_Invoices->utils->company_name($user_id, $user_type, $order); ?></strong></p>
                          <p><?php echo $WCMp_PDF_Invoices->utils->invoice_to_address($user_type, $user_id, ', ',$order);?></p><br/>
                      <?php }else{?>
                          <p class="invoice-text"><strong><?php _e('Invoice To:', 'wcmp-pdf_invoices'); ?> <?php echo $WCMp_PDF_Invoices->utils->company_name($user_id, $user_type, $order) ?></strong></p>
                          <p><?php echo $WCMp_PDF_Invoices->utils->invoice_to_address($user_type, $user_id, ', '); ?></p>
                      <?php } do_action('after_wcmp_pdf_invoice_to_address_details', $hook_data); ?>
                  </td>
                  <td align="right" class="invoice-info">
                      <?php do_action('before_wcmp_pdf_invoice_order_invoice_details', $hook_data); ?>
                      <h1><?php _e('INVOICE', 'wcmp-pdf_invoices'); ?></h1>
                      <?php $is_invoice_enable = get_wcmp_pdf_invoices_settings($user_id, 'is_invoice_no'); if($is_invoice_enable == 'Enable' && $invoice_data) : ?>
                      <h3># <?php echo $invoice_data['invoice_no']; ?></h3>
                      <?php endif; ?>
                      <table align="right">
                          <tbody>
                              <?php $is_invoice_enable = get_wcmp_pdf_invoices_settings($user_id, 'is_invoice_no'); if($is_invoice_enable == 'Enable' && $invoice_data) : ?>
                              <tr>
                                  <td><?php _e('Invoice date:', 'wcmp-pdf_invoices'); ?></td>
                                  <td><?php echo date_i18n(wc_date_format(), strtotime($invoice_data['invoice_date']->date)); ?></td>
                              </tr>
                              <?php endif; ?>
                              <tr>
                                  <td><?php _e('Order no:', 'wcmp-pdf_invoices'); ?></td>
                                  <td><?php echo $order->get_id(); ?></td>
                              </tr>
                              <tr>
                                  <td><?php _e('Order date:', 'wcmp-pdf_invoices'); ?></td>
                                  <td><?php echo date_i18n(wc_date_format(), strtotime($order->get_date_created())); ?></td>
                              </tr>
                              <?php $key = 'is_payment_method_'.$user_type; if(isset($settings[$key]) && $settings[$key] == 'Enable') : ?>
                              <tr>
                                  <td><?php _e('Payment method:', 'wcmp-pdf_invoices'); ?></td>
                                  <td><?php echo $order->get_payment_method_title(); ?></td>
                              </tr>
                              <?php endif; ?>
                              <?php do_action('after_wcmp_pdf_invoice_order_invoice_details', $hook_data); ?>
                          </tbody>
                      </table>
                  </td>
              </tr> 
          </table>
          
         <div class="product-detail-wrap <?php echo $hook_data["template"]; ?>">
          <table class="product-price-table">
              <thead>
                  <tr>
                      <?php do_action('before_wcmp_pdf_invoice_template_items_table_header', $hook_data); ?>
                      <th width="50%"><?php _e('Item', 'wcmp-pdf_invoices'); ?></th>
                      <th width="50%"><?php _e('SKU', 'wcmp-pdf_invoices'); ?></th>
                      <th align="center"><?php _e('Price', 'wcmp-pdf_invoices'); ?></th>
                      <th align="center"><?php _e('Quantity', 'wcmp-pdf_invoices'); ?></th>
                      <th align="right"><?php _e('Total', 'wcmp-pdf_invoices'); ?></th>
                      <?php do_action('after_wcmp_pdf_invoice_template_items_table_header', $hook_data); ?>
                  </tr>
              </thead>
              <tbody>
                  <?php $items = $WCMp_PDF_Invoices->utils->get_order_items($hook_data["order"]->get_id(),$hook_data["user_id"]); 
                  if( sizeof( $items ) > 0 ) : 
                  foreach( $items as $item_id => $item ) : $item_obj = $hook_data["order"]->get_item($item_id); ?>
                      <tr>
                          <?php do_action('before_wcmp_pdf_invoice_template_items_table_data', $hook_data); ?>
                          <td class="product">
                              <span class="item-name"><?php echo esc_html( $item_obj->get_name() ); ?></span>
                              <?php do_action( 'before_wcmp_pdf_invoice_template_item_meta', $hook_data["pdf_type"], $item, $hook_data["order"] ); ?>
                              <ul class="meta">
                              <?php $show_order_itemmeta = $WCMp_PDF_Invoices->utils->show_order_itemmeta();
                              if ( $meta_data = $item_obj->get_formatted_meta_data( '' ) ) :
                                  foreach ( $meta_data as $meta_id => $meta ) :
                                      if ( !in_array( $meta->key, $show_order_itemmeta, true ) ) {
                                          continue;
                                      }
                                      if($meta->key == '_vendor_id'){
                                          $meta->display_key = __('Sold by', 'wcmp-pdf_invoices');
                                          $vendor = get_wcmp_vendor($meta->value);
                                          $meta->display_value = $vendor->page_title;
                                      }
                              ?>
                              <li class="item-meta"><span><?php echo wp_kses_post( $meta->display_key ); ?>:</span> <span><?php echo wp_kses_post( force_balance_tags( $meta->display_value ) ); ?></span></li>
                              <?php endforeach; endif; ?>
                              </ul>
                              <?php do_action( 'after_wcmp_pdf_invoice_template_item_meta', $hook_data["pdf_type"], $item, $hook_data["order"] ); ?>
                          </td>
                          <?php
                          $product = $item_obj->get_product();
                          $sku = $product->get_sku();
                          if(empty($sku)) $sku = '-';
                          ?>
                          <td class="sku" align="left"><?php echo $sku; ?></td>
                          <td class="price" align="center"><?php echo wc_price( $hook_data["order"]->get_item_total( $item_obj, false, true ), array( 'currency' => $hook_data["order"]->get_currency() ) ); ?></td>
                          <td class="qunatity" align="center"><?php echo "&times; " . esc_html( $item_obj->get_quantity() ); ?></td>
                          <td class="total" align="right"><?php echo wc_price( $item_obj->get_total(), array( 'currency' => $hook_data["order"]->get_currency() ) ); ?></td>
                          <?php do_action('after_wcmp_pdf_invoice_template_items_table_data', $hook_data); ?>
                      </tr>
                  <?php endforeach; endif; ?>
              </tbody>
              <tfoot align="right">
                  <?php $order_item_totals = $WCMp_PDF_Invoices->utils->get_order_item_totals($hook_data["order"]->get_id(), $hook_data["user_id"], $hook_data["user_type"]);
                  if($order_item_totals) : 
                      foreach ($order_item_totals as $key => $total) { ?>
                          <tr>
                              <td colspan="3"></td>
                              <td><?php echo $total['label'];?></td>
                              <td><?php echo $total['value'];?></td>
                          </tr>
                      <?php }
                  endif;
                  ?>
              </tfoot>
          </table>
      </div>
          
          <div class="terms-text">
              <?php $key = 'is_customer_note_'.$user_type; if(isset($settings[$key]) && $settings[$key] == 'Enable' && $order->get_customer_note()) : ?>
                  <p><strong style="font-size: 13px; line-height: 16px;"><?php _e('Customer Note', 'wcmp-pdf_invoices'); ?></strong></p>
                  <p style="font-size: 12px; line-height: 16px;"><?php echo $order->get_customer_note(); ?></p>
              <?php endif; ?>   
              <?php if($WCMp_PDF_Invoices->utils->get_terms_n_conditions($user_type, $user_id)) : ?>   
                  <p style="margin-top: 15px;"><strong style="font-size: 13px; line-height: 16px;"><?php _e('Terms & Conditions', 'wcmp-pdf_invoices'); ?></strong></p>
                  <p style="font-size: 12px; line-height: 16px;"><?php echo $WCMp_PDF_Invoices->utils->get_terms_n_conditions($user_type, $user_id); ?></p>
              <?php endif; ?>
          </div>
          <?php do_action( 'after_wcmp_pdf_invoice_template', $hook_data ); ?> 
      </div>
      
      <!-- invoice2 start -->
      Copy

      Regards,

    • #108909
      Nathaniel George
      Participant
      This reply has been marked as private.
    • #108933
      abhirup
      Moderator

      Hi,
      Can you please share a staging site with the vendor access, admin access and FTP details where I can debug this issue.
      Do not forget mark as private to your reply while sharing the details.

      Regards,

    • #109001
      Nathaniel George
      Participant
      This reply has been marked as private.
    • #109118
      abhirup
      Moderator

      Hi,
      Can you please Share a video with what is issue, where did you saved the code and what is the setting of the default template of invoice.

      Regards,

Viewing 9 reply threads

Please LOGIN to reply to this topic