Adding phone field to checkout page (shipping)
-
Can someone help me! What is wrong with the code?
I have inserted this code to my child themes functions.php. Phone number field shows up correctly on the checkout page and “Saajan puhelin” text shows up on the admin panel order page. But the given phone number doesn’t show up on the admin panel order page.***************
// 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’ => __(‘Saajan puhelin’, ‘woocommerce’),
‘placeholder’ => _x(‘Anna matkapuhelinnumero’, ‘placeholder’, ‘woocommerce’),
‘required’ => false,
‘class’ => array(‘form-row-first’),
‘clear’ => true
);return $fields;
}function your_custom_field_function_name($order){
echo “<p>Saajan puhelin: ” . $order->order_custom_fields[‘_shipping_phone’][0] . “</p>”;
}add_action( ‘woocommerce_admin_order_data_after_shipping_address’, ‘your_custom_field_function_name’, 10, 1 );
***************
- The topic ‘Adding phone field to checkout page (shipping)’ is closed to new replies.