Title: Custom function in child theme
Last modified: August 21, 2016

---

# Custom function in child theme

 *  [kyunomi](https://wordpress.org/support/users/kyunomi/)
 * (@kyunomi)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/)
 * Hi,
 * I was trying to create a custom function in a child theme that i created.
 *     ```
       <?php
   
       add_action('woocommerce_order_details_after_order_table', 'My_additional_shipping_info');
   
       function My_additional_shipping_info() {
       	if ( $totals = $order->get_order_item_totals() ) {
       		if ($totals['shipping']['value']=="Self-Pickup @ Raffles Place MRT") {
       			echo 'Self-Pickup: ';
       		} else {
       			echo 'Delivery: ';
       		}
       	}
       	if ( $delivery_time = get_post_meta( $order->id, '_delivery_time', true ) ) {
       		echo "{$delivery_time}"; }
       }
       ?>
       ```
   
 * However, after i wrote it, the following error will occur
    Fatal error: Call 
   to a member function get_order_item_totals() on a non-object in /home/…/wp-content/
   themes/theme-child/functions.php
 * I guess it has something to do with me trying to call upon a function from wordpress
   without linking to it. but i dont know how to do it as i am still learning. would
   anyone kindly assists me? Thanks!

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

 *  [tamirster](https://wordpress.org/support/users/tamirster/)
 * (@tamirster)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/#post-4446171)
 * Start by moving
 *     ```
       add_action('woocommerce_order_details_after_order_table', My_additional_shipping_info');
       ```
   
 * to after the block of the function.
    so the code should look like:
 *     ```
       <?php
   
       function My_additional_shipping_info() {
       	if ( $totals = $order->get_order_item_totals() ) {
       		if ($totals['shipping']['value']=="Self-Pickup @ Raffles Place MRT") {
       			echo 'Self-Pickup: ';
       		} else {
       			echo 'Delivery: ';
       		}
       	}
       	if ( $delivery_time = get_post_meta( $order->id, '_delivery_time', true ) ) {
       		echo "{$delivery_time}"; }
       }
       add_action('woocommerce_order_details_after_order_table', 'My_additional_shipping_info');
       ?>
       ```
   
 *  Thread Starter [kyunomi](https://wordpress.org/support/users/kyunomi/)
 * (@kyunomi)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/#post-4446178)
 * yup i did. unfortunately, i still does not work.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/#post-4446180)
 * Where is `$order` defined? I’m assuming this is specific to a particular plugin
   and so have you asked this in that plugin’s subforum?
 *  Thread Starter [kyunomi](https://wordpress.org/support/users/kyunomi/)
 * (@kyunomi)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/#post-4446209)
 * i think both of them belong to woocommerce. Have not asked in the subforum yet
   as i thought this would be a general question of creating custom function in 
   a child theme which refers to a variable from wordpress or another plugin.

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

The topic ‘Custom function in child theme’ is closed to new replies.

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [custom function](https://wordpress.org/support/topic-tag/custom-function/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [kyunomi](https://wordpress.org/support/users/kyunomi/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/custom-function-in-child-theme/#post-4446209)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
