Home Forums WoodMart support forum PHP Notice when accessing an order via WP Admin

PHP Notice when accessing an order via WP Admin

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #535736

    bitnissen.com
    Participant

    Hi there,

    First off, thanks for an amazing theme!

    On a very simple and clean webshop in Woodmart 7.4.3, this notice appears in my development environment:

    Notice: Function ID was called incorrectly. Order properties should not be accessed directly. Backtrace: do_action('load-woocommerce_page_wc-orders'), WP_Hook->do_action, WP_Hook->apply_filters, Automattic\WooCommerce\Internal\Admin\Orders\PageController->__call, call_user_func_array, Automattic\WooCommerce\Internal\Admin\Orders\PageController->handle_load_page_action, Automattic\WooCommerce\Internal\Admin\Orders\PageController->setup_action_edit_order, Automattic\WooCommerce\Internal\Admin\Orders\PageController->prepare_order_edit_form, Automattic\WooCommerce\Internal\Admin\Orders\Edit->setup, do_action('add_meta_boxes'), WP_Hook->do_action, WP_Hook->apply_filters, XTS\Modules\Layouts\Admin->add_conditions_box, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /Users/mortenskyt/Local Sites/nembestil-menu/app/public/wp-includes/functions.php on line 6031
    

    It seems that the file:
    inc/modules/layouts/admin/class-admin.php

    On line 97 assumes that the second argument is a WP_Post object, while in fact it is a WooCommerce order object. Thus, using $post->ID is invalid. To fix the issue, just rewrite line 98 from:

    $type = get_post_meta( $post->ID, $this->type_meta_key, true );

    to

    $type = get_post_meta( $post->get_id(), $this->type_meta_key, true );

    Kind regards,
    Morten

    • This topic was modified 2 months, 4 weeks ago by bitnissen.com.
    #535757

    Artem Temos
    Keymaster

    Hello,

    Thank you so much for purchasing our theme and contacting our support center.

    This issue will be fixed in our next theme update. Thank you for your report.

    Kind Regards
    XTemos Studio

    #535789

    bitnissen.com
    Participant

    Hi again,

    Thanks for the quick reply!

    The fix is not good enough though :-/ Apparently it crashes when editing a Product, which uses the same method.

    So a better fix must detect the type of the $post argument, ie.:

    public function add_conditions_box( $post_type, $post ) {
      // get php instance type of $post
      $ID = get_class($post) === 'WP_Post' ? $post->ID : $post->get_id();
      $type = get_post_meta( $ID, $this->type_meta_key, true );

    Though this can likely be further improved. I’ll update if I stumble upon more cases where this isn’t sufficient 😉

    #535844

    Artem Temos
    Keymaster

    Thank you. Here is a fix that will be included in our next theme update https://gyazo.com/cc805a8a92473f3bb776da02251a4c61

    #535865

    bitnissen.com
    Participant

    Ah, good fix! Thanks for the info.

    #535886

    Artem Temos
    Keymaster

    You are welcome. Feel free to contact us if you have any further questions.

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘PHP Notice when accessing an order via WP Admin’ is closed to new replies.