不应直接访问订单属性 - WooCommerce 3.0 [英] Order properties should not be accessed directly - WooCommerce 3.0
问题描述
我刚刚将本地 WooCommerce 网站升级到 3.0.一切正常,但我注意到打开调试后,我收到了以下数百条通知:
I've just upgraded my local WooCommerce website to 3.0. Everything works perfectly as normal, but I've noticed with debugging turned on that I'm getting hundreds of the following notices:
[05-Apr-2017 12:25:00 UTC] PHP 通知:id 被错误地调用.不应直接访问订单属性.请参阅<a href="https://codex.wordpress.org/Debugging_in_WordPress">在 WordPress 中调试</a>想要查询更多的信息.(此消息是在 3.0 版本中添加的.)在 C:xampphtdocsdevwp-includesfunctions.php 中的第 4137 行
[05-Apr-2017 12:25:00 UTC] PHP Notice: id was called <strong>incorrectly</strong>. Order properties should not be accessed directly. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.0.) in C:xampphtdocsdevwp-includesfunctions.php on line 4137
所以看起来 WooCommerce 正在撤回能够直接调用订单数据的功能.触发此代码的一个示例是我的functions.php 文件中的此函数:
So it looks like WooCommerce are pulling back being able to directly call order data. One example this code is being triggered by is this function in my functions.php file:
function eden_woocommerce_order_number($original, $order)
{
return 'EDN-' . str_pad($order->id, 10, 0, STR_PAD_LEFT);
}
此函数只是将EDN"添加到订单 ID 的开头并将其填充 10 个字符,但 WooCommerce 不喜欢我调用 $order
的方式 - 什么是最好的怎样重写这样一个 3.0 满意的函数?
This function simply adds "EDN" to the start of the order ID and pads it by 10 characters, but WooCommerce doesn't like how I'm calling $order
- what would be the best way to rewrite such a function that 3.0 is happy with?
推荐答案
它说id 被错误地调用.不应直接访问订单属性."
it says "id was called incorrectly. Order properties should not be accessed directly."
试试$order->get_id()
这篇关于不应直接访问订单属性 - WooCommerce 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!