Skip to content

Instantly share code, notes, and snippets.

@MrJoshFisher
Created May 25, 2023 14:39
Show Gist options
  • Save MrJoshFisher/5217321e7eee83005351c2637dfae84c to your computer and use it in GitHub Desktop.
Save MrJoshFisher/5217321e7eee83005351c2637dfae84c to your computer and use it in GitHub Desktop.
[Add Custom Admin Column To Order Table] #woocommerce
//Add content
function action_woocommerce_admin_order_item_values( $product, $item, $item_id ) {
// WC_Order_Refund OR WC_Order_item
if ( $item->get_type() == 'shop_order_refund' ) {
$item = new WC_Order_Refund( $item_id );
} else {
$item = new WC_Order_Item_Product( $item_id );
// Only for "line_item" items type, to avoid errors
if ( ! $item->is_type( 'line_item' ) ) return;
}
if($product){
echo '<td class="line_packing_weight">('.round($product->get_weight()).'g) - '.round(($item['quantity'] * $product->get_weight())).'g</td>';
}
// Replace this part with your own code
}
add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment