【发布时间】:2021-04-06 12:15:04
【问题描述】:
我的订单包含我想调用以在我的订单页面上查看的信息。 但是这些信息不作为元数据存储,有没有办法获取这些信息?
我尝试了一些东西,但我总是遇到错误,这就是我尝试过的:
// ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column_another', 20 );
function custom_shop_order_column_another($columns)
{
$reordered_columns = array();
// Inserting columns to a specific location
foreach( $columns as $key => $column){
$reordered_columns[$key] = $column;
if( $key == 'order_status' ){
// Inserting after "Status" column
$reordered_columns['my-column3'] = __( 'Wefact email','theme_domain');
$reordered_columns['my-column4'] = __( 'Wefact status','theme_domain');
}
}
return $reordered_columns;
}
// Adding custom fields meta data for each new column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_Another_content', 20, 2 );
function custom_orders_list_column_Another_content( $column, $post_id )
{
switch ( $column )
{
case 'my-column3' :
// Get custom post meta data
$my_var_one = get_post_meta( $post_id, 'WeFact_email', true );
if(!empty($my_var_one))
echo $my_var_one;
// Testing (to be removed) - Empty value case
else
echo '<small>(<em>no value</em>)</small>';
break;
case 'my-column4' :
// Get custom post meta data
$wfInvoiceID = (int) get_post_meta( $post_id, '_wefact_invoice_id', true);
if (isset($wfInvoiceID)) :
$invoice = new WeFactInvoice();
$wfInvoice = $invoice->showByID($wfInvoiceID);
if ($wfInvoice['status'] == 'success') :
$status = [
"0" => "Concept factuur",
"1" => "Wachtrij factuur",
"2" => "Verzonden",
"3" => "Deels betaald",
"4" => "Betaald",
"8" => "Creditfactuur",
"9" => "Vervallen",
];
if(!empty($wfInvoiceID))
echo $status[$wfInvoice['invoice']['Status']];
// Testing (to be removed) - Empty value case
else
echo '<small>(<em>no value</em>)</small>';
break;
endif;
}
}
【问题讨论】:
标签: php wordpress woocommerce crud orders