I want to do some modifications to a template of WooCommerce, but I'm rather ZERO in PHP, so that is why I'm asking some guidance so I could perform my small modifications, which I'm sure are not too difficult.

So I have a plugin which generates me a PDF document from an invoice template, that invoice template is in PHP, so I need only 2 changes 1) Add extra field to that template. 2) Change a view a little bit

Start with 1, to add an extra field, so somewhere in this part I want to add that field:

<table class="order-data-addresses">
        <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->type, $this->order ); ?>
            <?php $this->billing_address(); ?>
            <?php do_action( 'wpo_wcpdf_after_billing_address', $this->type, $this->order ); ?>
            <?php if ( isset($this->settings['display_email']) ) { ?>
            <div class="billing-email"><?php $this->billing_email(); ?></div>
            <?php } ?>
            <?php if ( isset($this->settings['display_phone']) ) { ?>
            <div class="billing-phone"><?php $this->billing_phone(); ?></div>
            <?php } ?>
        <td class="address shipping-address">
            <?php if ( isset($this->settings['display_shipping_address']) && $this->ships_to_different_address()) { ?>
            <h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
            <?php do_action( 'wpo_wcpdf_before_shipping_address', $this->type, $this->order ); ?>
            <?php $this->shipping_address(); ?>
            <?php do_action( 'wpo_wcpdf_after_shipping_address', $this->type, $this->order ); ?>
            <?php } ?>
        <td class="order-data">
                <?php do_action( 'wpo_wcpdf_before_order_data', $this->type, $this->order ); ?>
                <?php if ( isset($this->settings['display_number']) ) { ?>
                <tr class="invoice-number">
                    <th><?php _e( 'Invoice Number:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
                    <td><?php $this->invoice_number(); ?></td>
                <?php } ?>
                <?php if ( isset($this->settings['display_date']) ) { ?>
                <tr class="invoice-date">
                    <th><?php _e( 'Invoice Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
                    <td><?php $this->invoice_date(); ?></td>
                <?php } ?>
                <tr class="order-number">
                    <th><?php _e( 'Order Number:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
                    <td><?php $this->order_number(); ?></td>
                <tr class="order-date">
                    <th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
                    <td><?php $this->order_date(); ?></td>
                <tr class="payment-method">
                    <th><?php _e( 'Payment Method:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
                    <td><?php $this->payment_method(); ?></td>
                <?php do_action( 'wpo_wcpdf_after_order_data', $this->type, $this->order ); ?>

I do know the name of the field, but I don't know how to integrate it here, the field is created with Checkout Field Editor. For example the name could be : billing_extra_field. I can add here a new row, but how do I access this field? I know this are probably very simple but I have no idea.

2) So on the invoice you can see what I have, this is more or less ok, BUT I want to change a little bit.

This part

Where is written subtotal, next to it I would like to have total without taxes + taxes And on final line I would like to remove (including tax xxxx)

This is the part of that template:

    <table class="order-details">
            <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>
        <?php $items = $this->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item_id => $item ) : ?>
        <tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', $item_id, $this->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->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 $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 $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif; ?>
                <?php do_action( 'wpo_wcpdf_after_item_meta', $this->type, $item, $this->order  ); ?>
            <td class="quantity"><?php echo $item['quantity']; ?></td>
            <td class="price"><?php echo $item['order_price']; ?></td>
        <?php endforeach; endif; ?>
        <tr class="no-borders">
            <td class="no-borders">
                <div class="customer-notes">
                    <?php do_action( 'wpo_wcpdf_before_customer_notes', $this->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->type, $this->order ); ?>
            <td class="no-borders" colspan="2">
                <table class="totals">
                        <?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
                        <tr class="<?php echo $key; ?>">
                            <td class="no-borders"></td>
                            <th class="description"><?php echo $total['label']; ?></th>
                            <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
                        <?php endforeach; ?>

<?php do_action( 'wpo_wcpdf_after_order_details', $this->type, $this->order ); ?>

I suppose this is also achievable because WordPress has all this info, you can choose to show it, but I only want to do it in this template.

I would really appreciate some advice.

  • Add the following code in your theme’s functions.php file – add_filter( 'woocommerce_get_order_item_totals', 'wc_get_order_item_totals', 10, 3 ); function wc_get_order_item_totals( $total_rows, $order, $tax_display ) { $total_rows['order_total'] = array( 'label' => __( 'Total:', 'woocommerce' ), 'value' => $order->get_formatted_order_total(), ); return $total_rows; } – vikrant zilpe Dec 12 '18 at 14:16
  • It did remove this (including TAX) for totals but it did not add to subtotals – Alnedru Dec 12 '18 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.