Advertisement
sierre

Add "Phone" field to Shipping / Different Address on Checkout

Apr 23rd, 2023
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. /* == Add Shipping Phone - WooCommerce == */
  2. add_filter( 'woocommerce_checkout_fields', 'sg_shipping_phone_checkout' );
  3.  
  4. function sg_shipping_phone_checkout( $fields ) {
  5.    $fields['shipping']['shipping_phone'] = array(
  6.       'label' => 'Phone',
  7.       'type' => 'tel',
  8.       'required' => true,
  9.       'class' => array( 'form-row-wide' ),
  10.       'validate' => array( 'phone' ),
  11.       'autocomplete' => 'tel',
  12.       'priority' => 25,
  13.    );
  14.    return $fields;
  15. }
  16.  
  17. add_action( 'woocommerce_admin_order_data_after_shipping_address', 'sg_shipping_phone_checkout_display' );
  18.  
  19. function sg_shipping_phone_checkout_display( $order ){
  20.     echo '<p><b>Shipping Phone:</b> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
  21. }
  22. /* == END: Add Shipping Phone - WooCommerce == */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement