1
votes

I have setup a custom payment method for WooCommerce, I don't have any PHP error during payment process but in received email by customer there is this error:

Notice: payment_method was called incorrectly. Order properties should not be accessed directly. Backtrace: edit_post, wp_update_post, wp_insert_post, do_action('save_post'), WP_Hook->do_action, WP_Hook->apply_filters, WC_Admin_Meta_Boxes->save_meta_boxes, do_action('woocommerce_process_shop_order_meta'), WP_Hook->do_action, WP_Hook->apply_filters, WC_Meta_Box_Order_Data::save, WC_Order->save, WC_Order->status_transition, do_action('woocommerce_order_status_on-hold_to_processing'), WP_Hook->do_action, WP_Hook->apply_filters, WC_Emails::send_transactional_email, do_action_ref_array('woocommerce_order_status_on-hold_to_processing_notification'), WP_Hook->do_action, WP_Hook->apply_filters, WC_Email_Customer_Processing_Order->trigger, WC_Email->get_content, WC_Email_Customer_Processing_Order->get_content_html, wc_get_template_html, wc_get_template, include('/plugins/woocommerce/templates/emails/customer-processing-order.php'), do_action('woocommerce_email_order_details'), WP_Hook->do_action, WP_Hook->app in /home/username/public_html/site/wp-includes/functions.php on line 5167

And this is code for email content and full code is available here:

public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {

    if ( $this->instructions && ! $sent_to_admin && $this->id === $order->get_payment_method && $order->has_status( 'on-hold' ) ) {
        echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
    }
}

I have changed $order->payment_method to $order->get_payment_method but still receive the error.

Could you please guide me to debug it?

1

1 Answers

1
votes
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {

    if ( $this->instructions && ! $sent_to_admin && $this->id === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
        echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
    }
}

Please try modifying like this. get_payment_method()