WooCommerce Custom Fields Display
This WordPress plugin extends WooCommerce by adding a custom field column to the orders list on the My Account page and displaying the custom field value on the Order Details page. It requires WooCommerce to be installed and uses hooks to integrate the custom field into the order management interface.
<?php /** * Plugin Name: CodeWP WooCommerce Order Custom Fields Display (OOP Version) * Plugin URI: https://codewp.ai * Description: Display custom fields from orders on the WooCommerce My Account page and Order Details page, reworked as an Object-Oriented Plugin. * Version: 1.0 * Author: CodeWP Assistant * Author URI: https://codewp.ai */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class CodeWP_WooCommerce_Custom_Fields_Display { /** * Constructor for the class. */ public function __construct() { if ( class_exists( 'WooCommerce' ) ) { add_filter( 'woocommerce_account_orders_columns', [ $this, 'add_custom_field_to_orders_column' ] ); add_action( 'woocommerce_my_account_my_orders_column_custom-field', [ $this, 'display_custom_field_in_orders_list' ] ); add_action( 'woocommerce_order_details_after_order_table', [ $this, 'display_custom_field_on_order_details' ] ); } } /** * Add a new column for the custom field in the orders list. * * @param array $columns Existing columns. * @return array Modified columns. */ public function add_custom_field_to_orders_column( $columns ) { $columns['custom-field'] = __( 'Custom Field', 'codewp' ); return $columns; } /** * Display the custom field value in the orders list. * * @param WC_Order $order Order object. */ public function display_custom_field_in_orders_list( $order ) { $custom_field_value = $order->get_meta( 'your_custom_field', true ); $custom_field_value = 'testing'; if ( ! empty( $custom_field_value ) ) { echo esc_html( $custom_field_value ) ; } } /** * Display the custom field value on the order details page. * * @param WC_Order $order Order object. */ public function display_custom_field_on_order_details( $order ) { $custom_field_value = $order->get_meta( 'your_custom_field', true ); if ( ! empty( $custom_field_value ) ) { echo '<p><strong>' . __( 'Custom Field', 'codewp' ) . ':</strong> ' . esc_html( $custom_field_value ) . '</p>'; } } } new CodeWP_WooCommerce_Custom_Fields_Display();
Frequently Asked Questions
This plugin adds a custom field column to WooCommerce orders on the My Account page and displays its value on the Order Details page.