1 回答
TA贡献1828条经验 获得超6个赞
我不是很明白get_the_terms
. get_type()
应该足够了。
// Add header
function action_woocommerce_admin_order_item_headers( $order ) {
echo '<th class="line_mytitle sortable" data-sort="your-sort-option">My Title</th>';
}
add_action( 'woocommerce_admin_order_item_headers', 'action_woocommerce_admin_order_item_headers', 10, 1 );
//Add content
function action_woocommerce_admin_order_item_values( $product, $item, $item_id ) {
$order = $item->get_order();
?>
<td class="item_cost_price" width="1%" data-sort-value="<?php echo esc_attr( $order->get_item_subtotal( $item, false, true ) ); ?>">
<div class="view">
<?php
if( ! is_null( $product ) ) {
// Get product type
$product_type = $product->get_type();
echo 'product type = ' . $product_type . '<br>';
if( $product_type == 'variation' ) {
$variation_id = $item->get_variation_id();
echo wc_price( get_post_meta( $variation_id, 'variation_cost', true ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif( $product_type == 'simple' ) {
echo wc_price( get_post_meta( $item->get_product_id(), 'cost_price', true ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
echo "No aplica";
}
} else {
echo 'No aplica';
}
?>
</div>
</td>
<?php
}
add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 );
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报