• 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 );

    ***************

    https://www.ads-software.com/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Thread Starter uraT

    (@urat)

    Thank you Mike! Now I tried code like this. But the situation is the same. I’m not a coder… so could you tell me what is wrong now?

    **************
    // 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;
    }

    add_action(‘woocommerce_admin_order_data_after_shipping_address’, ‘my_custom_shipping_fields_display_admin_order_meta’, 10, 1);

    function my_custom_shipping_fields_display_admin_order_meta($order) {
    echo ‘<p>‘ . __(‘Saajan puhelin’) . ‘:
    ‘ . get_post_meta($order->id, ‘_shipping_phone’, true) . ‘</p>’;
    }
    ***************

    Plugin Contributor Mike Jolley

    (@mikejolley)

    What do you see on screen now? Looks better.

    Thread Starter uraT

    (@urat)

    On the checkout page everything is correct and I can see “Saajan puhelin” text on the admin panel. But not the given phone number :-/

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Are you sure _shipping_phone is the correct meta key? Have you confirmed its set in the postmeta table?

    Thread Starter uraT

    (@urat)

    No I haven’t… And I don’t know how to do it. Maybe it is better to install a plugin for this… ??
    Thank you anyway Mike!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding phone field to checkout page (shipping)’ is closed to new replies.