• Resolved dschiffner

    (@dschiffner)


    Hi there @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 7 years, 4 months ago by dschiffner.
    • This topic was modified 7 years, 4 months ago by dschiffner.
    • This topic was modified 7 years, 4 months ago by dschiffner.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    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.

    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

    (@dschiffner)

    Thanks so much for your reply!

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a variable string’ is closed to new replies.