Title: Exec Custom field
Last modified: August 31, 2016

---

# Exec Custom field

 *  Resolved [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/)
 * Hi!
    I installed the plugin Uni CPO – WooCommerce Options and Price Calculation
   Formulas – [http://codecanyon.net/item/uni-cpo-woocommerce-options-and-price-calculation-formulas/9333768](http://codecanyon.net/item/uni-cpo-woocommerce-options-and-price-calculation-formulas/9333768)
   for calculate the price with additional fields like data and text input. For 
   example, i created a text field (uni_cpo_summa_str). How to specify this field
   in my php code of template? Like a $billing_ssumma = get_post_meta($wpo_wcpdf-
   >export->order->id,’_uni_cpo_summa_str’,true); ? This don’t work
 * [https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)

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

 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221592)
 * In order items post meta this field looks like
    » Сумма страхования
 * How to extract in pdf invoice this field?
    This code extract all fields – <?php
   echo $item[‘meta’];?> But i need the one
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221619)
 * I found a solution whit code:
 *     ```
       <?php
       $items = $wpo_wcpdf->get_order_items();
       if( sizeof( $items ) > 0 ) {
       	foreach( $items as $item ) {
       		if (isset($item['item']['item_meta']['Сумма страхования'])) {
       			echo $item['item']['item_meta']['Сумма страхования'][0] . '<br />';
       		}
       		if (isset($item['item']['item_meta']['Name'])) {
       			echo 'Name: ' . $item['item']['item_meta']['Name'][0] . '<br />';
       		}
       	}
       }
       ?>
       ```
   
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221629)
 * But how to get the value of the srok (the number of months)? The code below don’t
   work
 *     ```
       <?php
       $items = $wpo_wcpdf->get_order_items();
       if( sizeof( $items ) > 0 ) {
       	foreach( $items as $item ) {
       			$srok = $item['item']['item_meta']['Срок страхования, мес.'];
       			if ( $srok == '12') {
       			$final = date("d.m.Y", strtotime("+12 month -1 day", $billing_ot) );}
   
       		}
       }
       ?>
       ```
   
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221704)
 * Looks like $billing_ot isn’t loaded anywhere in this code!
    I would recommend
   using `wpo_wcpdf_after_item_meta` (which also gets the $item as a parameter) 
   in combination with [wc_get_order_item_meta()](https://wordpress.org/support/topic/display-order-item-meta-data-in-custom-invoice-template-how?replies=6#post-7892704)
 * Hope that helps!
    Ewout
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221712)
 * $billing_ot loaded earlier (just the code not shown):
    `$billing_ot = get_post_meta(
   $wpo_wcpdf->export->order->id,'_billing_field_474',true);`
 * The code below shows the value of $srok but how to use it in logical operations:
 *     ```
       <?php
       $items = $wpo_wcpdf->get_order_items();
       if( sizeof( $items ) > 0 ) {
       	foreach( $items as $item ) {
       		if (isset($item['item']['item_meta']['Сумма страхования'])) {
       			echo $item['item']['item_meta']['Сумма страхования'][0] . '&nbsp;₽';
       		}
       		if (isset($item['item']['item_meta']['Name'])) {
       			echo 'Name: ' . $item['item']['item_meta']['Name'][0] . '<br />';
       		}
       	}
       }?>
       ```
   
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221717)
 * This code works:
 *     ```
       <?php
       $items = $wpo_wcpdf->get_order_items();
       if( sizeof( $items ) > 0 ) {
       	foreach( $items as $item ) {
       		if (isset($item['item']['item_meta']['Срок страхования, мес.'])) {
       			$srok = $item['item']['item_meta']['Срок страхования, мес.'][0];}
       			echo $srok;
       			if ( $srok == '3') {
       			$final = date("d.m.Y", strtotime("+3 month -1 day", $billing_ot) );}
       			if ( $srok == '6') {
       			$final = date("d.m.Y", strtotime("+6 month -1 day", $billing_ot) );}
   
       	}
       }?>
       ```
   
 * But date set as: 31-03-2016 to 31.03.1970
    Why the year 1970, and not 2016?
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221719)
 * Wow, this code works:
 *     ```
       <?php
       $items = $wpo_wcpdf->get_order_items();
       if( sizeof( $items ) > 0 ) {
       	foreach( $items as $item ) {
       		if (isset($item['item']['item_meta']['Срок страхования, мес.'])) {
       			$srok = $item['item']['item_meta']['Срок страхования, мес.'][0];}
       			echo $srok;
   
       $invoice_date = get_post_meta($wpo_wcpdf->export->order->id,'_wcpdf_invoice_date',true);
       if ( $srok == '3') {
       $final = date_i18n( get_option( 'date_format' ), strtotime( $billing_ot . ' + 3 months -1 day') );}
       if ( $srok == '6') {
       $final = date_i18n( get_option( 'date_format' ), strtotime( $billing_ot . ' + 6 months -1 day') );}
       if ( $srok == '9') {
       $final = date_i18n( get_option( 'date_format' ), strtotime( $billing_ot . ' + 9 months -1 day') );}
       }
       }
       ?>
       ```
   
 * Last question. How to format 01-04-2016 to 01.04.2016 in pdf invoice?
    And how
   to format 01.04.2016 to 01-04-2016 in pdf invoice?
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221753)
 * ?
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221754)
 * `get_option( 'date_format' )` takes the setting from WordPress under Settings
   > General. You can use ‘d.m.Y’ or ‘d-m-Y’ instead too if you like.
 * Ewout
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221755)
 * No, this code…
    `$final = date_i18n( get_option( 'date_format' ), strtotime( 
   $billing_ot . ' + 9 months -1 day') );}`
 * It gives the date as 01-04-16
    How to format $final to 01.04.06?
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221756)
 * It seems to work)
 *     ```
       $search = array(".");
       $replace = array("-");
       $final = str_replace($search, $replace, $final);
       ```
   
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221757)
 * Hi Alexey, like I said, that date format call
 *     ```
       get_option( 'date_format' )
       ```
   
 * is taking your WordPress settings. If you need a different format than in your
   wordpress settings, you can simply enter the format directly (instead of calling
   the option):
 *     ```
       $final = date_i18n( 'd-m-Y', strtotime( $billing_ot . ' + 9 months -1 day') );}
       ```
   
 * Have a great weekend 🙂
    Ewout
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221758)
 * Thanks, Ewout!
 * Have a great weekend!

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

The topic ‘Exec Custom field’ 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/)

 * 13 replies
 * 2 participants
 * Last reply from: [Nitrat](https://wordpress.org/support/users/nitrat/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/exec-custom-field/#post-7221758)
 * Status: resolved