我四处张望,现在感到愚蠢。因此,我试图使用this将自定义字段添加到结帐中。因此,我可以看到该字段,并且效果很好。但是问题是当我尝试在管理面板中查看客户输入的信息时。我正在使用simply show hooks查看触发了哪些钩子,依此类推。而且我看不到woocommerce_admin_order_data_after_shipping_address
触发。我想念的是什么?!这是我的functions.php
:
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 ) {
unset($fields['billing']['billing_address_2']);
unset($fields['shipping']['shipping_address_2']);
$fields['billing']['shipping_time'] = array(
'type' => 'select',
'label' => __('Laikas', 'woocommerce'),
'placeholder' => _x('Laikas', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true,
'options' => array(
'option_1' => 'nesvarbu',
'option_2' => '8-12',
'option_3' => '12-16',
'option_4' => '16-20'
)
);
return $fields;
}
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){
global $post_id;
$order = new WC_Order( $post_id );
echo '<p><strong>'.__('Laikas').':</strong> ' . get_post_meta($order->get_id(), '_shipping_ftime', true ) . '</p>';
}
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 ) {
unset( $fields[ 'billing' ][ 'billing_address_2' ] );
unset( $fields[ 'shipping' ][ 'shipping_address_2' ] );
$fields[ 'billing' ][ 'shipping_time' ] = array(
'type' => 'select',
'label' => __( 'Laikas', 'woocommerce' ),
'placeholder' => _x( 'Laikas', 'placeholder', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-wide' ),
'clear' => true,
'options' => array(
'option_1' => 'nesvarbu',
'option_2' => '8-12',
'option_3' => '12-16',
'option_4' => '16-20'
)
);
return $fields;
}
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 ) {
global $post_id;
$order = new WC_Order( $post_id );
$options = array(
'option_1' => 'nesvarbu',
'option_2' => '8-12',
'option_3' => '12-16',
'option_4' => '16-20'
);
echo '<p><strong>' . __( 'Laikas' ) . ':</strong> ' . $options[get_post_meta( $order->get_id(), '_shipping_time', true )] . '</p>';
}
请尝试此代码段。