admin管理员组

文章数量:1122832

On the order details page, i’d like to display the customer email in a distinct div in raw format
and add a little copy-to-clipboard jQuery plugin like on the attached screenshot

I played around with this portion of code below which outputs customer details. It is found in

class-wc-meta-box-order-data.php

<div class="address">
                        <?php
                        // Display values.
                        if ( $order->get_formatted_billing_address() ) {
                            echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
                        } else {
                            echo '<p class="none_set"><strong>' . esc_html__( 'Address:', 'woocommerce' ) . '</strong> ' . esc_html__( 'No billing address set.', 'woocommerce' ) . '</p>';
                        }

                        $billing_fields = self::get_billing_fields( $order, 'view' );

                        foreach ( $billing_fields as $key => $field ) {
                            if ( isset( $field['show'] ) && false === $field['show'] ) {
                                continue;
                            }

                            $field_name = 'billing_' . $key;

                            if ( isset( $field['value'] ) ) {
                                $field_value = $field['value'];
                            } elseif ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
                                $field_value = $order->{"get_$field_name"}( 'edit' );
                            } else {
                                $field_value = $order->get_meta( '_' . $field_name );
                            }

                            if ( 'billing_phone' === $field_name ) {
                                $field_value = wc_make_phone_clickable( $field_value );
                            } elseif ( 'billing_email' === $field_name ) {
                                $field_value = '<a href="' . esc_url( 'mailto:' . $field_value ) . '">' . $field_value . '</a>';
                            } else {
                                $field_value = make_clickable( esc_html( $field_value ) );
                            }

                            if ( $field_value ) {
                                echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
                            }
                        }
                        ?>
                    </div>

I tried to extract just the email address but my php level is pretty basic so I haven’t been able to get the email field by itself

On the order details page, i’d like to display the customer email in a distinct div in raw format
and add a little copy-to-clipboard jQuery plugin like on the attached screenshot

I played around with this portion of code below which outputs customer details. It is found in

class-wc-meta-box-order-data.php

<div class="address">
                        <?php
                        // Display values.
                        if ( $order->get_formatted_billing_address() ) {
                            echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
                        } else {
                            echo '<p class="none_set"><strong>' . esc_html__( 'Address:', 'woocommerce' ) . '</strong> ' . esc_html__( 'No billing address set.', 'woocommerce' ) . '</p>';
                        }

                        $billing_fields = self::get_billing_fields( $order, 'view' );

                        foreach ( $billing_fields as $key => $field ) {
                            if ( isset( $field['show'] ) && false === $field['show'] ) {
                                continue;
                            }

                            $field_name = 'billing_' . $key;

                            if ( isset( $field['value'] ) ) {
                                $field_value = $field['value'];
                            } elseif ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
                                $field_value = $order->{"get_$field_name"}( 'edit' );
                            } else {
                                $field_value = $order->get_meta( '_' . $field_name );
                            }

                            if ( 'billing_phone' === $field_name ) {
                                $field_value = wc_make_phone_clickable( $field_value );
                            } elseif ( 'billing_email' === $field_name ) {
                                $field_value = '<a href="' . esc_url( 'mailto:' . $field_value ) . '">' . $field_value . '</a>';
                            } else {
                                $field_value = make_clickable( esc_html( $field_value ) );
                            }

                            if ( $field_value ) {
                                echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
                            }
                        }
                        ?>
                    </div>

I tried to extract just the email address but my php level is pretty basic so I haven’t been able to get the email field by itself

Share Improve this question asked Jul 5, 2024 at 11:17 Decoy_Octopus_Decoy_Octopus_ 1
Add a comment  | 

1 Answer 1

Reset to default 0

woocommerce_admin_order_data_after_shipping_address is the hook you're looking for.

add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_function' );

function my_function( $order ) {
    echo '<div class="jquery-copy"><input type="text" readonly value="' . esc_attr( $order->get_billing_email() ) . '"></div>';
}

There's a chance you might want to use $order->get_shipping_email() instead.

本文标签: woocommerce offtopicHow to display customer email within the meta order data box