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_ 11 Answer
Reset to default 0woocommerce_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
版权声明:本文标题:woocommerce offtopic - How to display customer email within the meta order data box 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301557a1931220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论