Home › Forums › WoodMart support forum › PHP Notice when accessing an order via WP Admin
PHP Notice when accessing an order via WP Admin
- This topic has 5 replies, 2 voices, and was last updated 10 months, 2 weeks ago by Artem Temos.
-
AuthorPosts
-
February 1, 2024 at 11:26 am #535736
bitnissen.comParticipantHi 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 10 months, 2 weeks ago by bitnissen.com.
February 1, 2024 at 12:28 pm #535757
Artem TemosKeymasterHello,
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 StudioFebruary 1, 2024 at 1:53 pm #535789
bitnissen.comParticipantHi 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 😉
- This reply was modified 10 months, 2 weeks ago by bitnissen.com.
- This reply was modified 10 months, 2 weeks ago by bitnissen.com.
February 1, 2024 at 3:31 pm #535844
Artem TemosKeymasterThank you. Here is a fix that will be included in our next theme update https://gyazo.com/cc805a8a92473f3bb776da02251a4c61
February 1, 2024 at 3:51 pm #535865
bitnissen.comParticipantAh, good fix! Thanks for the info.
February 1, 2024 at 4:12 pm #535886
Artem TemosKeymasterYou are welcome. Feel free to contact us if you have any further questions.
-
AuthorPosts
Tagged: php notice
The topic ‘PHP Notice when accessing an order via WP Admin’ is closed to new replies.
- You must be logged in to create new topics. Login / Register