Title: Creating a variable string
Last modified: November 2, 2017

---

# Creating a variable string

 *  Resolved [dschiffner](https://wordpress.org/support/users/dschiffner/)
 * (@dschiffner)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/creating-a-variable-string/)
 * Hi there [@pomegranate](https://wordpress.org/support/users/pomegranate/) or 
   anyone else who can help,
 * This may be a very simple question – but I’m finding myself dumbfounded.
 * On my own custom pdf invoice template, I’m try to create a variable… or simply
   dump certain values in strings to use in some conditional statements.
 * For example, the template has **$wpo_wcpdf->order_number();** and I would like
   to use the order number to pull some other information.
    Likewise with a custom
   field I have made – $this->custom_field(‘Chosen Pickup Location’);
 * Both of these will print out the correct information on the page when used, but
   they can’t be made into string variables to use if statements etc
 * As an example of what I’m trying to do:
    $location = $this->custom_field(‘Chosen
   Pickup Location’); if ($location == get_the_title($post->ID)){ … }
 * Any ideas of what I’m looking over?
    -  This topic was modified 8 years, 5 months ago by [dschiffner](https://wordpress.org/support/users/dschiffner/).
    -  This topic was modified 8 years, 5 months ago by [dschiffner](https://wordpress.org/support/users/dschiffner/).
    -  This topic was modified 8 years, 5 months ago by [dschiffner](https://wordpress.org/support/users/dschiffner/).

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

 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/creating-a-variable-string/#post-9648687)
 * Hi!
    First of all, I recommend to update your custom template to match the 2.0
   format, you can find some details about this [here](https://wpovernight.com/2017/06/woocomerce-pdf-invoice-2-0-beta-testers-wanted/#whatsnew).
 * Methods like `$this->order_number()` and `$this->custom_field()` are display 
   functions that should not be used to retrieve data as a variable – they both 
   actually use similarly named getter functions `$this->get_order_number()` and`
   $this->get_custom_field()` (so both with `get_` prefixed to the method name.
 * In you case though, I would recommend directly using the WC order getters. Here
   are some snippets that should help:
 *     ```
       $order_id = $this->order->get_id(); (note that this is not necessarily equal to the order number! This is what you should use for most code relating to getting post data.
       $order_number = $this->order->get_order_number();
       $location = $this->order->get_meta('Chosen Pickup Location');
       ```
   
 * As you can see you can directly access the $order object via $this->order, this
   gives you the most freedom.
 * Hope that helps!
    Ewout
 *  Thread Starter [dschiffner](https://wordpress.org/support/users/dschiffner/)
 * (@dschiffner)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/creating-a-variable-string/#post-9649776)
 * Thanks so much for your reply!
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/creating-a-variable-string/#post-9657157)
 * You’re welcome!

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

The topic ‘Creating a variable string’ 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/)

## Tags

 * [custom data](https://wordpress.org/support/topic-tag/custom-data/)
 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)

 * 3 replies
 * 2 participants
 * Last reply from: [Ewout](https://wordpress.org/support/users/pomegranate/)
 * Last activity: [8 years, 5 months ago](https://wordpress.org/support/topic/creating-a-variable-string/#post-9657157)
 * Status: resolved