我有一个关于woocommerce和wordpress本身的问题。可能我的问题是虚拟的,但目前的代码不起作用。将wordpress post_meta显示到其他表中
我想要实现的是在woocommerce订单子页面中显示我的自定义字段数据。我的自定义字段post_meta有名称(metakey):wccpf_authorvalue
在谷歌我已经找到了一些代码,只需要改变我的帖子元名字变成这样:
add_filter('manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION');
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset($new_columns['order_actions']);
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['for-author-value'] = 'Dla autora';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action('manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2);
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post;
$data = get_post_meta($post->ID);
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ($column == 'for-author-value') {
echo (isset($data['wccpf_authorvalue']) ? $data['wccpf_authorvalue'] : '');
}
}
add_filter("manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION');
function MY_COLUMNS_SORT_FUNCTION($columns) {
$custom = array(
//start editing
'for-author-value' => 'wccpf_authorvalue'
//stop editing
);
return wp_parse_args($custom, $columns);
}
的问题 - 列显示,但没有任何价值。这是为什么?
我用这里的解决方案:Stackoverflow.com但它不工作。
你给出的代码对我来说工作正常。你有没有检查'wccpf_authorvalue'是否被保存在数据库中或者是否有与该**键**的元? –
@Rohil_PHPBeginner - 在DB> _postmeta表中我有我的记录与元值如({“type”:“text”,“label”:“PLN dla autora”,“name”:“pl ..)。也是表woocommerce_order_itemmeta其中 - >每个订单都有专门的记录到我的输入(元值是我需要的数据)但我不知道如何显示它,特别是如果每个订单都有自己的专用线 –
替换'$ data = get_post_meta($ post-> ID);''用'$ data = get_post_meta($ post-> ID,'wccpf_authorvalue',true);''和'echo $ data;'。您能否给我结果替换之后? –