• Resolved maxdass

    (@maxdass)


    Hi,
    I’d like to extract the booking dates because I need it in my invoice.php (made with WooCommerce PDF Invoices & Packing Slips).

    I’d like to add this type of information :
    Delivery date = “booking start_date”

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter maxdass

    (@maxdass)

    Already tried to open a booking_session in invoice.php but I have an Internal server error when I submit my order

    Plugin Author Ashanna

    (@morki)

    Hello,

    Please have a look at the right support forum: https://herownsweetcode.com/easy-booking/topic/get-the-start-and-end-date-for-export/.

    Regards,
    Natasha

    Thread Starter maxdass

    (@maxdass)

    OK, it does not work for me, this is my code included in invoice.php :
    <?PHP $order = new WC_Order( $order_id );
    $items = $order->get_items();

    if ( $items ) foreach ( $items as $item_id => $item ) {

    }?>

    <th><?php _e( ‘Date de livraison:’, ‘wpo_wcpdf’ ); ?></th>
    <td><?PHP wc_get_order_item_meta( $item_id, ‘_ebs_start_display’, true ); ?>

    It remains blank on my PDF

    • This reply was modified 8 years, 1 month ago by maxdass.
    Plugin Author Ashanna

    (@morki)

    Well yes, you’re outside the foreach loop… Try this:

    <?php
    
    $order = wc_get_order( $order_id );
    $items = $order->get_items();
    
    if ( $items ) foreach ( $items as $item_id => $item ) {
        echo '<th>' . __( 'Date de livraison:', 'wpo_wcpdf' ) . '</th>';
        echo '<td>' . wc_get_order_item_meta( $item_id, '_ebs_start_display', true ) . '</td>';
    }
    
    ?>
    • This reply was modified 8 years, 1 month ago by Ashanna.
    Thread Starter maxdass

    (@maxdass)

    Hi thanks but it does not work, I have an “internal server error” when I add this code.

    Plugin Author Ashanna

    (@morki)

    But I’ve tried and the order item meta (including booking dates) are already displayed by the plugin in the generated invoices, why would you want to add them again?

    Without the whole code, I can’t help more sorry.

    Thread Starter maxdass

    (@maxdass)

    Yes I see that they are already displayed.

    I need to add a line outside the table with the delivery date.
    And the delivery date is the same as the start_date (booking date).

    It has to appear in my invoices like this :

    CLIENT NAME
    BOOKING N°XX
    DELIVERY DATE

    INVOICE TABLE

    Many thanks for your help

    Plugin Author Ashanna

    (@morki)

    Ok, I see…

    It depends where exactly you want to put this on the invoice, there are multiple action hooks available.

    You can try this:

    add_action( 'wpo_wcpdf_after_order_data', 'display_booking_date_in_invoice', 10, 2 );
    
    function display_booking_date_in_invoice( $template_type, $order ) {
    
        $items = $order->get_items();
    
        if ( $items ) foreach ( $items as $item_id => $item ) {
            echo '<tr>';
            echo '<th>' . __( 'Date de livraison:', 'wpo_wcpdf' ) . '</th>';
            echo '<td>' . wc_get_order_item_meta( $item_id, '_ebs_start_display', true ) . '</td>';
            echo '</tr>';
        }
    				
    }

    This will display what you need under the order information.

    Please note that booking dates are stored per item, and not per order, which means that if you have several booked items in your order it will display several dates.

    Edit: Don’t put the code directly in the invoice.php file but in your theme’s functions.php.

    • This reply was modified 8 years, 1 month ago by Ashanna.
    • This reply was modified 8 years, 1 month ago by Ashanna.
    Thread Starter maxdass

    (@maxdass)

    Yes it works !

    Now the problem is that I have several dates as you said.

    I just added break; and it works.
    Even If there is 2 items in my order, my delivery date appears only once.

    Thanks a lot for your help

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to extract dates’ is closed to new replies.