我从本教程中逐步完成了所有步骤:https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('Phone From Checkout Form').':</strong> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
}
一切正常,但是......我想在订单页面的快速视图中显示新字段的价值,我找到的所有教程,只显示如何在订单的详细信息页面上显示它们。
谢谢!
答案 0 :(得分:0)
我找到了在订单预览框中显示自定义字段的操作:
add_action( 'woocommerce_admin_order_preview_start', 'custom_display_order_data_in_admin' );
或:
add_action( 'woocommerce_admin_order_preview_end', 'custom_display_order_data_in_admin' );
但是您可能会注意到,这两个操作将在其开头或结尾添加自定义字段。
编辑: 我在自定义插件中使用的整个代码是这样的:
function custom_display_order_data_in_admin( $order ){ ?>
<div class="order_data_column">
<div class="address">
<?php
echo '<p><strong>' . __( 'billing cart' ) . ':</strong>' . get_post_meta( $order->id, '_billing_cart', true ) . '</p>';
?>
</div>
<div class="edit_address">
<?php woocommerce_wp_text_input( array( 'id' => '_billing_cart', 'label' => __( 'billing cart' ), 'wrapper_class' => '_billing_company_field' ) ); ?>
</div>
</div>
<?php }
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_display_order_data_in_admin' );
add_action( 'woocommerce_admin_order_preview_end', 'custom_display_order_data_in_admin' );
您应该只更改自己的代码中使用的参数