• Resolved patdundee

    (@patdundee)


    Hi Guys
    I am trying to add more info to the invoice layout I have managed to get the required_date (extra filed) added in to the invoice under the order date. However I am trying to get it located afte the order_comments field (this is an extra woocommerce field set in woocommerce after shipping details.

    This is what i have that works after order date at the top of the invoice

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_required_date', 10, 2 );
    function wpo_wcpdf_required_date ($template_type, $order) {
        if ($template_type == 'invoice') {
            ?>
            <tr class="delivery-date">
                <th>Required Date:</th>
                <td><?php echo $order->get_meta('required_date'); ?></td>
            </tr>
            <?php
        }
    }

    However when i try this to go further down the invoice after order_details it tells me there is a problem on the site and does not work

    add_action( 'wpo_wcpdf_after_order_comments', 'wpo_wcpdf_required_date', 10, 2 );
    function wpo_wcpdf_required_date ($template_type, $order) {
        if ($template_type == 'invoice') {
            ?>
            <tr class="delivery-date">
                <th>Required Date:</th>
                <td><?php echo $order->get_meta('required_date'); ?></td>
            </tr>
            <?php
        }
    }
    • This topic was modified 6 years, 8 months ago by patdundee.
    • This topic was modified 6 years, 8 months ago by patdundee.
    • This topic was modified 6 years, 8 months ago by patdundee.
    • This topic was modified 6 years, 8 months ago by patdundee.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    There is no wpo_wcpdf_after_order_comments action hook, which is why this doesn’t work. There’s one named wpo_wcpdf_after_customer_notes, perhaps that works for you too? There’s a list of available action hooks here: PDF template action hooks

    Thread Starter patdundee

    (@patdundee)

    Hi Thanks for the reply. That stopped the problem on the site error. But,
    If i try to put the required date anywhere except for the header with a hook I now get the following error when trying to view the PDF (it is in download mode) when i select download i get the below error

    DOMPDF Exception: Min/max width is undefined for table rows
    Followed by these lines

    #0 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\TableRow->get_min_max_width()
    #1 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/AbstractFrameReflower.php(268): Dompdf\FrameDecorator\AbstractFrameDecorator->get_min_max_width()
    #2 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\AbstractFrameReflower->get_min_max_width()
    #3 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/AbstractFrameReflower.php(268): Dompdf\FrameDecorator\AbstractFrameDecorator->get_min_max_width()
    #4 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(903): Dompdf\FrameReflower\AbstractFrameReflower->get_min_max_width()
    #5 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/Cellmap.php(645): Dompdf\FrameDecorator\AbstractFrameDecorator->get_min_max_width()
    #6 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/Cellmap.php(518): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\TableCell))
    #7 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/Cellmap.php(518): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\TableRow))
    #8 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/Cellmap.php(518): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\TableRowGroup))
    #9 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/Table.php(532): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\Table))
    #10 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/Table.php(408): Dompdf\FrameReflower\Table->get_min_max_width()
    #11 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Table->reflow(Object(Dompdf\FrameDecorator\Block))
    #12 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/Block.php(845): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow(Object(Dompdf\FrameDecorator\Block))
    #13 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Block->reflow(NULL)
    #14 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameReflower/Page.php(141): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow()
    #15 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Page->reflow(NULL)
    #16 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/vendor/dompdf/dompdf/src/Dompdf.php(847): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow()
    #17 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/class-wcpdf-pdf-maker.php(53): Dompdf\Dompdf->render()
    #18 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(615): WPO\WC\PDF_Invoices\PDF_Maker->output()
    #19 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(650): WPO\WC\PDF_Invoices\Documents\Order_Document->get_pdf()
    #20 /home/www/kimboscakes.co.uk/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/class-wcpdf-main.php(337): WPO\WC\PDF_Invoices\Documents\Order_Document->output_pdf(‘download’)
    #21 /home/www/kimboscakes.co.uk/wp-includes/class-wp-hook.php(286): WPO\WC\PDF_Invoices\Main->generate_pdf_ajax(”)
    #22 /home/www/kimboscakes.co.uk/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
    #23 /home/www/kimboscakes.co.uk/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
    #24 /home/www/kimboscakes.co.uk/wp-admin/admin-ajax.php(173): do_action(‘wp_ajax_generat…’)
    #25 {main}

    Plugin Contributor Ewout

    (@pomegranate)

    That’s probably because you’re trying to insert table rows where there is no table.

    
    add_action( 'wpo_wcpdf_after_customer_notes', 'wpo_wcpdf_required_date', 10, 2 );
    function wpo_wcpdf_required_date ($template_type, $order) {
        if ($template_type == 'invoice') {
            ?>
            <h3>Required Date:</h3>
            <div><?php echo $order->get_meta('required_date'); ?></div>
            <?php
        }
    }
    
    Thread Starter patdundee

    (@patdundee)

    Hi
    That worked great “I never thought of that one”

    Just as a point of interest, not sure if you are aware, if I try to add the action after order_data (Top of invoice under order date) and also try to add the action elsewhere i get the error from the first message. It tells me “it tells me there is a problem on the site and does not work. Stops site from running.”

    It would seem you can only call the get_meta(‘required_date’) just the once.

    Many thanks
    P

    Plugin Contributor Ewout

    (@pomegranate)

    You can hook into multiple actions, just make sure not to define the same function more than once. Either call to the same function (which you can’t do in this case, because of the table vs. regular layout) with the two action hooks, or use two different function names.

    Thread Starter patdundee

    (@patdundee)

    Many thanks πŸ™‚

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘New action hook’ is closed to new replies.