• Resolved marpessa1

    (@marpessa1)


    Hello and thanks for the fantastic plugin. I’m using a custom invoice template and all is working fine except the “shipping_state”. I’m using a customized state list and it works fine throughout the site. However, when I want to display it as a custom field in the template with the following code, it shows up blank. I checked the order page and it shows up as a custom field with “shipping_state” just fine. I can succesfully call all other custom fields with the following code but only this won’t work. Any idea why that might be? Thanks in advance.

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date', 10, 2 );
    function wpo_wcpdf_delivery_date ($template_type, $order) {
        if ($template_type == 'invoice') {
            $document = wcpdf_get_document( $template_type, $order );
            ?>      
            <tr class="delivery-date">
                <th>Shipping State:</th>
                <td><?php $document->custom_field('shipping_state'); ?></td>
            </tr>
            <?php
        }
    }

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

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

    (@pomegranate)

    Hello Marpessa,
    The custom_field method uses various fallback mechanisms because some ‘custom fields’ have a special status within WooCommerce orders and should be called with property getters. shipping_state is such an order property (which is stored in the order as _shipping_state with an underscore).
    In this case it’s better to use the WooCommerce functions directly because you do not want all these fallback mechanisms to apply :).

    Can you try this?

    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_shipping_state', 10, 2 );
    function wpo_wcpdf_shipping_state ($template_type, $order) {
        if ($template_type == 'invoice') {
            ?>      
            <tr class="delivery-date">
                <th>Shipping State:</th>
                <td><?php echo $order->get_meta('shipping_state'); ?></td>
            </tr>
            <?php
        }
    }
    
    Thread Starter marpessa1

    (@marpessa1)

    Ah that worked! Thank you very much for the perfect support!

    Plugin Contributor Ewout

    (@pomegranate)

    Very glad to hear that! If you can spare a minute, I would really appreciate a plugin review here on www.ads-software.com. Thanks in advance and have a fantastic rest of the week!

    Thread Starter marpessa1

    (@marpessa1)

    Will do!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can’t get “shipping_state” custom field’ is closed to new replies.