Adding product attribute column to edit order page in Woocommerce(将产品属性列添加到WooCommerce中的编辑订单页面)
本文介绍了将产品属性列添加到WooCommerce中的编辑订单页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
非常感谢您在这方面的任何帮助。
到目前为止,尝试了许多方法都没有效果,包括这里的建议:
Add product short description to Woocommerce admin orders preview
这是我到目前为止所拥有的:
add_action( 'woocommerce_admin_order_item_headers', 'custom_admin_order_items_headers', 20, 1 );
function custom_admin_order_items_headers( $order ){
echo '<th>';
echo __('Colour', 'woocommerce') . '</th>';
}
add_action( 'woocommerce_admin_order_item_values', 'custom_admin_order_item_values', 20, 3 );
function custom_admin_order_item_values( $_product, $item, $item_id ) {
$colour = $_product->get_attribute( 'colour' );
echo '<td>' . $colour . '</td>';
}
每个产品都有多个属性,我要在"编辑订单"页的新列中显示其中一个属性。
问题是,由于某种原因,产品属性为空-如果我只是回显$_PRODUCT,则该属性中没有数据,即使它肯定有一个值保存在数据库中。
有什么想法吗?
我已经附上了我想要实现的目标的屏幕截图,虽然我可以让标题显示得很好,甚至可以将数据数组附加到产品上,但实际属性是空的。如果我使用:
$_product->get_attribute( 'colour' )
就像我在站点上的其他地方成功地做的那样,我收到一个错误:
Uncaught Error: Call to a member function get_attribute() on null
我尝试设置全局$PRODUCT;在函数中,没有。
错误日志:
致命错误:未捕获错误:调用/home/customer/www/mysite/public_html/wp-content/themes/mytheme/functions.php:1237堆栈跟踪中对NULL的成员函数GET_ATTRIBUTE():#0/home/customer/www/mysite/public_html/wp-includes/class-wp-hook.php(288):CUSTOM_ADMIN_ORDER_ITEM_VALUES(NULL,对象(WC_ORDER_ITEM_SHIPING),26)#1/home/mysite/public_html/wp-includes/class-wp-hook.php(312):WP_HOOK->;应用过滤器(‘’,数组)#2/home/customer/www/mysite/public_html/wp-includes/plugin.php(478):WP_挂钩->;Do_action(数组)#3/home/customer/www/mysite/public_html/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-shipping.php(53):do_action(‘WooCommerce_adm...’,NULL,Object(WC_Order_Item_Shipping),26)#4/home/customer/www/mysite/public_html/wp-content/plugins/woocommerce/includes/admin/meta-boxes/views/html-order-items.php(73):包括(‘/HOME/Customer/...’)#5/HOME/Customer/www/MySite in/home/customer/www/mysite/public_html/wp-content/themes/mytheme/functions.php,第1237行
第1237行,共functions.php
行为:
$colour = $_product->get_attribute( 'colour' );
如上所述。
推荐答案
这对我有效:
add_action('woocommerce_admin_order_item_values', 'my_woocommerce_admin_order_item_values', 10, 3);
function my_woocommerce_admin_order_item_values($_product, $item, $item_id = null) {
$colour = get_the_terms( $_product->post->ID, 'pa_colour');
echo '<td>' . $colour[0]->name . '</td>';
}
必须沿着分类法的路线前进,而不是GET_ATTRIBUTE()。感谢这篇文章:
show product meta in order items table in Order Details
这篇关于将产品属性列添加到WooCommerce中的编辑订单页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将产品属性列添加到WooCommerce中的编辑订单页面


猜你喜欢
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01