Call to a member function get_cart() Your Site is Experiencing a Technical Issue
-
Hi,
When I am changing the order status in woocommerce from processing to completed I am receiving the below error. Even Order completed notification email to client is also not working.
Please help me to fix the issue.
Error Details
=============An error of type E_ERROR was caused in line 70 of the file /home/hanaa006/public_html/wp-content/themes/betheme-child/yith-woocommerce-email-templates/emails/email-order-details.php. Error message: Uncaught Error: Call to a member function get_cart() on null in /home/hanaa006/public_html/wp-content/themes/betheme-child/yith-woocommerce-email-templates/emails/email-order-details.php:70 Stack trace: #0 /home/hanaa006/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include() #1 /home/hanaa006/public_html/wp-content/plugins/woocommerce/includes/class-wc-emails.php(383): wc_get_template(’emails/email-or…’, Array) #2 /home/hanaa006/public_html/wp-includes/class-wp-hook.php(286): WC_Emails->order_details(Object(WC_Order), false, false, Object(WC_Email_Customer_Completed_Order)) #3 /home/hanaa006/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #4 /home/hanaa006/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #5 /home/hanaa006/public_html/wp-content/plugins/woocommerce/templates/emails/customer-completed-order.php(39): do_action(‘woocommerce_ema…’, Object(WC_Order), false, false, Object(WC_Email_Customer_Completed_Order))
-
Hi @frenzymermaids!
Did you modify or override the
email-order-details.php
file? If so, please paste the code you are using back here so we can take a closer look, thanks.Cheers!
Hi Rynald0s,
Thanks for your reply. Please check the code. Many thanks in advance for your kind support.
<?php /** * Order details table shown in emails. * * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-details.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @version 3.3.1 */ if ( !defined( 'ABSPATH' ) ) { exit; } global $current_email; $template = yith_wcet_get_email_template( $current_email ); $meta = yith_wcet_get_template_meta( $template ); $show_thumbs = ( isset( $meta[ 'show_prod_thumb' ] ) ) ? $meta[ 'show_prod_thumb' ] : false; $premium_mail_style = ( !empty( $meta[ 'premium_mail_style' ] ) ) ? $meta[ 'premium_mail_style' ] : 0; $titles = array( 'product' => esc_html__( 'Product', 'woocommerce' ), 'quantity' => esc_html__( 'Quantity', 'woocommerce' ), 'price' => esc_html__( 'TOTAL', 'woocommerce' ) ); foreach ( $titles as $key => $value ) { $titles[ $key ] = apply_filters( 'yith_wcet_order_details_table_title_' . $key, $value, $order, $sent_to_admin, $plain_text, $email ); } do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?> <?php if ( apply_filters( 'yith_wcet_order_details_show_order_title', true, $order, $sent_to_admin, $plain_text, $email ) ): ?> <h2> <?php if ( $sent_to_admin ) { $before = '<a>get_edit_order_url() ) . '">'; $after = '</a>'; } else { $before = ''; $after = ''; } /* translators: %s: Order ID. */ echo wp_kses_post( $before . sprintf( __( 'Order #%s', 'woocommerce' ) . $after . ' (<time datetime="%s">%s</time>)', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) ); ?> </h2> <?php endif; ?> <table class="shop_table woocommerce-checkout-review-order-table"> <thead> <tr class="tm-epo-cart-row-header"> <th class="product-thumbnail"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th> <th class="product-name"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th> <th class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th> <th class="product-subtotal"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th> <?php do_action( 'tm_woocommerce_cart_after_column_header'); ?> </tr> </thead> <tbody> <?php do_action( 'woocommerce_before_cart_contents' ); ?> <?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); $variation_id = $cart_item['variation_id']; if (empty($variation_id)){ $variation_id = $product_id; } $original_product = wc_get_product($variation_id); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) { $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key ); ?> <tr class="tm-epo-cart-row-product woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <td class="product-thumbnail"> <?php $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key ); if ( ! $product_permalink ) { echo wp_kses_post( $thumbnail ); } else { printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), wp_kses_post( $thumbnail ) ); } ?> </td> <td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>"> <?php if ( ! $product_permalink ) { echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . ' ' ); } else { echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) ); } do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key ); // Meta data. echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok. // Backorder notification. if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) { echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>' ) ); } ?> </td> <td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>"> <?php if (TM_EPO()->tm_epo_hide_options_in_cart=="normal"){ echo apply_filters( 'wc_tm_epo_ac_product_price', apply_filters( 'woocommerce_cart_item_price', TM_EPO()->get_price_for_cart( $cart_item['tm_epo_product_original_price'], $cart_item, ""), $cart_item, $cart_item_key ), $cart_item_key, $cart_item, $original_product, $product_id ); }else{ echo apply_filters( 'wc_tm_epo_ac_product_price', apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ), $cart_item_key, $cart_item, $_product, $product_id ); } ?> </td> <td class="product-quantity" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>"> <?php echo apply_filters( 'wc_tm_epo_ac_product_qty', $cart_item['quantity'], $cart_item_key, $cart_item, $_product, $product_id ) ; ?> </td> <td class="product-subtotal" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"> <?php if (TM_EPO()->tm_epo_cart_field_display=="advanced"){ if (TM_EPO()->tm_epo_hide_options_in_cart=="normal"){ if (isset($cart_item['tm_epo_product_after_adjustment']) && isset(TM_EPO()->tm_epo_dpd_enable) && TM_EPO()->tm_epo_dpd_enable=="no"){ $price = $cart_item['tm_epo_product_after_adjustment']; }else{ $price=apply_filters('wc_epo_discounted_price', $cart_item['tm_epo_product_original_price'], wc_get_product(tc_get_id($cart_item['data'])), $cart_item_key, true); } $price=$price*$cart_item['quantity']; echo apply_filters( 'wc_tm_epo_ac_subtotal_price', apply_filters( 'woocommerce_cart_item_subtotal', TM_EPO()->get_price_for_cart( $price,$cart_item,""), $cart_item, $cart_item_key), $cart_item_key, $cart_item, $_product, $product_id ); }else{ echo apply_filters( 'wc_tm_epo_ac_subtotal_price', apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ), $cart_item_key, $cart_item, $_product, $product_id ); } }else{ echo apply_filters( 'wc_tm_epo_ac_subtotal_price', apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $original_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ), $cart_item_key, $cart_item, $_product, $product_id ); } ?> </td> <?php do_action( 'tm_woocommerce_cart_after_column', $cart_item_key, $cart_item, $_product, $product_id ); ?> </tr> <?php do_action( 'tm_woocommerce_cart_after_row', $cart_item_key, $cart_item, $_product, $product_id ); } } ?> </tbody> <?php if ( $premium_mail_style < 2 ): ?> <tfoot> <?php if ( $totals = $order->get_order_item_totals() ) { $i = 0; $t_count = count( $totals ); foreach ( $totals as $total ) { $i++; $last_class = $i == $t_count ? 'last' : 'not_last'; ?> <tr> <th class="yith-wcet-order-items-table-element<?php if ( $i == 1 ) echo ''; ?> <?php echo $last_class; ?>" scope="row" colspan="2"><?php echo wp_kses_post( $total[ 'label' ] ); ?></th> <td class="yith-wcet-order-items-table-element<?php if ( $i == 1 ) echo ''; ?> <?php echo $last_class; ?>"><?php echo wp_kses_post( $total[ 'value' ] ); ?></td> </tr><?php } } ?> </tfoot> <?php endif ?> </table> <?php if ( $premium_mail_style > 1 ): $totals_table_width_percentage = absint( apply_filters( 'yith_wcet_order_details_table_totals_table_width_percentage', '50', $current_email, $premium_mail_style ) ); $first_column_width_percentage = 100 - $totals_table_width_percentage; ?> <table width="100%"> <tr> <td width="100%"></td> </tr> </table> <table class="yith-wcet-two-columns" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="<?php echo $first_column_width_percentage ?>%" style="padding:0px"> </td> <td width="<?php echo $totals_table_width_percentage ?>%" style="padding:0px"> <table id="yith-wcet-foot-price-list"> <?php if ( $totals = $order->get_order_item_totals() ) { $i = 0; $t_count = count( $totals ); foreach ( $totals as $total ) { $i++; $last_class = $i == $t_count ? 'last' : 'not_last'; $total_label = str_replace( ':', '', $total[ 'label' ] ); $total_label = apply_filters( 'yith_wcet_total_label', $total_label, $current_email ); ?> <tr> <th <?php if ( $i == $t_count ) { echo 'id="yith-wcet-total-title"'; } ?> class="<?php echo $last_class; ?>" scope="row" colspan="2"><?php echo wp_kses_post( $total_label ); ?></th> <td <?php if ( $i == $t_count ) { echo 'id="yith-wcet-total-price"'; } ?> class="<?php echo $last_class; ?>"><?php echo wp_kses_post( $total[ 'value' ] ); ?></td> </tr><?php } } ?> </table> </td> </tr> </table> <?php endif ?> <?php if ( $order->get_customer_note() ) : ?> <table width="100%"> <tr> <td width="100%"></td> </tr> </table> <table id="yith-wcet-order-customer-note-table" cellspacing="0" cellpadding="6" style="width: 100%;"> <tr> <td> <h2><?php _e( 'Note:', 'woocommerce' ) ?></h2> <p><?php echo wp_kses_post( wptexturize( $order->get_customer_note() ) ) ?></p> </td> </tr> </table> <?php endif ?> <?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
Hi there,
Going over custom code isn’t something that we’re able to assist with here on the forums.
You may want to look into hiring a dev – (https://woocommerce.com/customizations/)
But I’d ask this over in the Advanced WooCommerce Facebook Group, first – (https://www.facebook.com/groups/advanced.woocommerce/)Best,
Ross
- The topic ‘Call to a member function get_cart() Your Site is Experiencing a Technical Issue’ is closed to new replies.