Title: Query shipping method
Last modified: May 12, 2021

---

# Query shipping method

 *  Resolved [Corbett Enders](https://wordpress.org/support/users/cenders/)
 * (@cenders)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/query-shipping-method/)
 * I love your plug in. I’m adding a custom field to the PDFs generated but I would
   like to query the shipping method and only show the field if the shipping is 
   not pickup. This doesn’t seem to work, where am I going wrong? I’ve tried outputting
   the variable $shipping_method to see what it contains and it appears to be empty.
 * add_action( ‘wpo_wcpdf_before_order_details’, ‘wpo_wcpdf_location’, 10, 2 );
   
   function wpo_wcpdf_location ($template_type, $order) { $document = wcpdf_get_document(
   $template_type, $order ); $shipping_method = $order->get_shipping_method(); if(
   $shipping_method !== ‘local_pickup’) { ?> <b>Delivery Location:</b> <?php $document-
   >custom_field(‘Delivery Location’); ?><br><br> <?php } }`

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

 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/query-shipping-method/#post-14435982)
 * Hi [@cenders](https://wordpress.org/support/users/cenders/),
 * I believe this is what you’re looking for:
 *     ```
       add_action('wpo_wcpdf_after_order_data', 'wpo_wcpdf_show_shipping_method', 10, 2); 
       function wpo_wcpdf_show_shipping_method ( $template_type, $order ) {
       	// if order is empty, bail!
       	if ( empty($order) ) {return;}
   
       	foreach ( $order->get_shipping_methods() as $shipping_method ) {
       		$shipping_method_name = $shipping_method->get_name();
       		if ( strtolower($shipping_method_name) !== 'local pickup' ) {
       			?>
       			<tr class="shipping-method">
       				<th>Shipping Method: </th>
       				<td><?php echo $shipping_method_name; ?></td>
       			</tr>
       			<?php
       		}
       	}
       }
       ```
   
 *  Thread Starter [Corbett Enders](https://wordpress.org/support/users/cenders/)
 * (@cenders)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/query-shipping-method/#post-14436142)
 * Thank you! That works.
 * Actual code I used is:
 *     ```
       add_action('wpo_wcpdf_after_order_data', 'wpo_wcpdf_show_shipping_method', 10, 2); 
       function wpo_wcpdf_show_shipping_method ( $template_type, $order ) {
       	// if order is empty, bail!
       	if ( empty($order) ) {return;}
       	$document = wcpdf_get_document( $template_type, $order );
       	foreach ( $order->get_shipping_methods() as $shipping_method ) {
       		$shipping_method_name = $shipping_method->get_name();
       		if ( strtolower($shipping_method_name) === 'delivery' ) {
       			?><tr><td colspan="2"><br><b><?php $document->custom_field('Delivery Location'); ?></b></td></tr>
       			<?php
       		}
       	}
       }
       ```
   
    -  This reply was modified 5 years, 1 month ago by [Corbett Enders](https://wordpress.org/support/users/cenders/).

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

The topic ‘Query shipping method’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Corbett Enders](https://wordpress.org/support/users/cenders/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/query-shipping-method/#post-14436142)
 * Status: resolved