Title: &#8216;Add fee&#8217; breaks website
Last modified: July 15, 2020

---

# ‘Add fee’ breaks website

 *  Resolved [businesscloudinc](https://wordpress.org/support/users/businesscloudinc/)
 * (@businesscloudinc)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/add-fee-breaks-website/)
 * I have added the below code so I would be able to use the product title in the
   email templates
 *     ```
       //Custom email format
       add_filter( 'woocommerce_email_format_string' , 'add_custom_email_format_string', 10, 2 );
       function add_custom_email_format_string( $string, $email ) {
           $order       = $email->object; // Get the instance of the WC_Order OBJECT
           $order_items = $order->get_items(); // Get Order items
           $order_item  = reset($order_items); // Get the irst order item
   
           $string = str_replace( '{subscription_name}', $order_item->get_name(), $string );
   
           return $string; 
       }
       ```
   
 * However, if I add an order manually and add a fee instead of a product, and try
   to send the customer invoice / order details email to the customer to pay, my
   website throws an error that it has run into a critical error and points this
   line of code to be the issue:
 * `$string = str_replace( '{subscription_name}', $order_item->get_name(), $string);`
 * The exact error is:
 *     ```
       Error Details
       =============
       An error of type E_ERROR was caused in line 573 of the file
       /wp-content/themes/Divi-child/functions.php.
       Error message: Uncaught Error: Call to a member function get_name() on
       bool in /public_html/quest/wp-content/themes/Divi-child/functions.php:573
       Stack trace:
       #0 /public_html/quest/wp-includes/class-wp-hook.php(287):
       add_custom_email_format_string('Your latest QUE...',
       Object(WC_Email_Customer_Invoice))
       #1 /public_html/quest/wp-includes/plugin.php(206):
       WP_Hook->apply_filters('Your latest QUE...', Array)
       #2 /public_html/quest/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(310):
       apply_filters('woocommerce_ema...', 'Your latest QUE...',
       Object(WC_Email_Customer_Invoice))
       #3 /public_html/quest/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-invoice.php(90):
       WC_Email->format_string('Your latest {si...')
       #4 /public_html/quest/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-invoice.php(139):
       WC_Email_Customer_Invoice->get_subject()
       #5 /public_html/quest/wp-content
       ```
   
 * How can I modify this so I can still use the product name in some of the emails
   but still be able to add custom fees when needed? I need to use the ‘add fee’
   option to send custom payment amounts to clients for grandfathered subscriptions.
    -  This topic was modified 5 years, 10 months ago by [businesscloudinc](https://wordpress.org/support/users/businesscloudinc/).
      Reason: added error details

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

 *  Plugin Support [slash1andy](https://wordpress.org/support/users/slash1andy/)
 * (@slash1andy)
 * Automattic Happiness Engineer
 * [5 years, 10 months ago](https://wordpress.org/support/topic/add-fee-breaks-website/#post-13133208)
 * This is a fairly complex development topic. I’m going to leave it open for a 
   bit to see if anyone is able to chime in to help you out.
 * I can also recommend the following places for more development-oriented questions:
    1. WooCommerce Slack Community: [https://woocommerce.com/community-slack/](https://woocommerce.com/community-slack/)
    2. WooCommerce FB group: [https://www.facebook.com/groups/advanced.woocommerce/](https://www.facebook.com/groups/advanced.woocommerce/)
 *  Thread Starter [businesscloudinc](https://wordpress.org/support/users/businesscloudinc/)
 * (@businesscloudinc)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/add-fee-breaks-website/#post-13133355)
 * Thanks for the resources! I got a recommendation on Slack to make the following
   change and that resolved the issue:
 *     ```
       if( is_object( $order_item ) && method_exists( $order_item, 'get_name' ) ) {
         $string = str_replace( '{subscription_name}', $order_item->get_name(), $string );
       }
       ```
   

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

The topic ‘‘Add fee’ breaks website’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [businesscloudinc](https://wordpress.org/support/users/businesscloudinc/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/add-fee-breaks-website/#post-13133355)
 * Status: resolved