• Resolved Danny

    (@dannyfoo)


    I’ve added the following code to the template-functions.php as per documentation for my invoice:

    add_action( 'wpo_wcpdf_after_shipping_address', 'wpo_wcpdf_location_name', 10, 2 );
    function wpo_wcpdf_location_name ($template_type, $order) {
            ?>
            <tr class="location-name">
                <th>Pickup Location:</th>
                <td><?php echo $order->get_meta('_pickup_location_name'); ?></td>
            </tr>
        <?php
    }

    And I’ve got my invoice set to HTML to view the render faster. But nothing is displayed – not even the ‘Pickup Location’ text.

    But if I changed the hook to ‘wpo_wcpdf_before_customer_notes’ I can see the text at least. While custom field value is still not loading.

    Is there something else I’m missing?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @dannyfoo,

    You’re using a wrong syntax for this area, using a table markup, but this is only required in the order data area.

    Please replace your code snippet with this adapted version:

    add_action( 'wpo_wcpdf_after_shipping_address', 'wpo_wcpdf_location_name', 10, 2 );
    function wpo_wcpdf_location_name( $template_type, $order ) {
    	printf( '<div>Pickup Location: %s</div>', $order->get_meta('_pickup_location_name') );
    }
    Thread Starter Danny

    (@dannyfoo)

    Hey @yordansoares thank you for jumping on this.

    I tried the adapted code. But nothing appeared under the Shipping Address.

    I added the line printf( ‘Test’ ); to see if anything comes out – nothing.

    Then I swapped the action to ‘wpo_wcpdf_before_customer_notes’ and the printf(‘Test’) returned, but not the custom meta.

    So there seems to be an issue with the action hook and returning of custom meta.

    • This reply was modified 3 years, 6 months ago by Danny. Reason: Forgot to add even custom meta is not returned
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @dannyfoo,

    Please note that the shipping address should to be displayed in order to see the output added through the code snippet, that is hidden by default if it’s the same than the billing address. To ensure that the shipping address is always displayed, go to WooCommerce > PDF Invoices > Documents > Invoices > Display shipping address > Always.

    Thread Starter Danny

    (@dannyfoo)

    Hey @yordansoares

    Do you mean that if I used the hook ‘wpo_wcpdf_after_shipping_address’, no additional info will display after it unless the Display Shipping Address Always is enabled?

    Because circling back to this bit of code you suggested:

    add_action( 'wpo_wcpdf_after_shipping_address', 'wpo_wcpdf_location_name', 10, 2 );
    function wpo_wcpdf_location_name( $template_type, $order ) {
    	printf( '<div>Pickup Location: %s</div>', $order->get_meta('_pickup_location_name') );
    }

    I want the pickup location name to show after the Shipping Address.

    • This reply was modified 3 years, 6 months ago by Danny.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Do you mean that if I used the hook ‘wpo_wcpdf_after_shipping_address’, no additional info will display after it unless the Display Shipping Address Always is enabled?

    That’s right. This is because, by default, the shipping address will be hidden if the bot billing and shipping info are the same: This need to be displayed in the document in order to show what the code snippet adds.

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

The topic ‘Can’t add Local Pickup Plus custom field to wpo_wcpdf_after_shipping_address’ is closed to new replies.