‘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-contentHow 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.
The topic ‘‘Add fee’ breaks website’ is closed to new replies.