• Resolved irishetcher

    (@irishetcher)


    I see many comment on this and it’s really bad UX. Providing a phone number for couriers to contact the recipients prior to delivery is a given.

    Yes there is the phone number for the Billing address but there is also the occasion where there will be a different number for the recipient.

    I have started to research the solutions to this and have found the following.

    add_filter( 'woocommerce_checkout_fields', 'bbloomer_shipping_phone_checkout' );
     
    function bbloomer_shipping_phone_checkout( $fields ) {
       $fields['shipping']['shipping_phone'] = array(
          'label' => 'Phone for Delivery',
          'required' => true,
          'class' => array( 'form-row-wide' ),
          'priority' => 25,
       );
       return $fields;
    }
      
    add_action( 'woocommerce_admin_order_data_after_shipping_address', 'bbloomer_shipping_phone_checkout_display' );
     
    function bbloomer_shipping_phone_checkout_display( $order ){
        echo '<p><b>Shipping Phone:</b> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
    }

    That is a good start but, two things.

    1. it place the phone number after the name and not down further so that it balances in the design opposite the Billing phone number.

    2. This phone number doesn’t get echoed into the notification emails. You need to log in to the orders to collect this info, whereas I have the notifications to copy in with the email of a third party to fulfil the order and they don’t have access to the site backend.

    You can see the problem and honestly, it’s such a small but crucial feature of the sales and fulfilment fuel that we should not have to hack this into WooCommerce.

    I’m surprised!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can move the phone field further down the form by changing the value for priority. Try 100 instead of 25.

    Next, add the phone field to the order meta:

    add_action( 'woocommerce_new_order', 'add_shipping_phone_to_order' );
    function add_shipping_phone_to_order( $order_id ) {
      $shipping_phone = isset( $_POST['shipping_phone'] ) ? $_POST['shipping_phone'] : 'Not set';
      add_post_meta( $order_id, 'shipping_phone', $shipping_phone, true ); 
    }

    Then add the order meta to the emails:

    add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
      $fields['shipping_phone'] = array(
       'label' => 'Shipping Phone',
       'value' => get_post_meta( $order->get_id(), 'shipping_phone', true ),
      );
      return $fields;
    }

    It shows above the shipping address I’m afraid.

    laceyrod

    (@laceyrod)

    Automattic Happiness Engineer

    Hi @irishetcher

    Since we haven’t heard back from you, and this thread has been inactive for a bit, I’m going to mark it as Resolved now for the overall health of the forums. Please feel free to open a new one if you have any further questions.

    Cheers!

    Thread Starter irishetcher

    (@irishetcher)

    Thanks for the prompt. I didn’t seem to be getting email notifications. I found a plugin to do this but, now I see Lorro’s suggestion above. I was tempted to change that 25 number but though it referred to something else!

    Cheers.

    • This reply was modified 3 years, 10 months ago by irishetcher.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘No Phone for delivery’ is closed to new replies.