Guest User

Untitled

a guest
Sep 23rd, 2015
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Add phone # fields
  2. add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
  3. function custom_override_checkout_fields( $fields ) {
  4.     $fields['billing']['cell_phone'] = array(
  5.     'label'     => __('Cell Phone', 'woocommerce'),
  6.     'placeholder'   => _x('', 'placeholder', 'woocommerce'),
  7.     'required'  => false,
  8.     'class'     => array('form-row-first'),
  9.     'clear'     => false
  10.      );
  11.     $fields['billing']['biz_phone'] = array(
  12.     'label'     => __('Business Phone', 'woocommerce'),
  13.     'placeholder'   => _x('', 'placeholder', 'woocommerce'),
  14.     'required'  => false,
  15.     'class'     => array('form-row-last'),
  16.     'clear'     => true
  17.      );
  18.      return $fields;
  19. }
  20.  
  21. // Update the order meta with field value for cell phone
  22. add_action( 'woocommerce_checkout_update_order_meta', 'cell_phone_field_update_order_meta' );
  23. function cell_phone_field_update_order_meta( $order_id ) {
  24.     if ( ! empty( $_POST['cell_phone'] ) ) {
  25.         update_post_meta( $order_id, 'Cell Phone', sanitize_text_field( $_POST['cell_phone'] ) );
  26.     }
  27. }
  28.  
  29. // Update the order meta with field value for biz phone
  30. add_action( 'woocommerce_checkout_update_order_meta', 'biz_phone_field_update_order_meta' );
  31. function biz_phone_field_update_order_meta( $order_id ) {
  32.     if ( ! empty( $_POST['biz_phone'] ) ) {
  33.         update_post_meta( $order_id, 'Business Phone', sanitize_text_field( $_POST['biz_phone'] ) );
  34.     }
  35. }
  36.  
  37. // Display cell phone # on the order edit page
  38. add_action( 'woocommerce_admin_order_data_after_billing_address', 'cell_phone_field_display_admin_order_meta', 10, 1 );
  39. function cell_phone_field_display_admin_order_meta($order){
  40.     echo '<p><strong>'.__('Cell Phone').':</strong> ' . get_post_meta( $order->id, 'Cell Phone', true ) . '</p>';
  41. }
  42.  
  43. // Display biz phone # on the order edit page
  44. add_action( 'woocommerce_admin_order_data_after_billing_address', 'biz_phone_field_display_admin_order_meta', 10, 1 );
  45. function biz_phone_field_display_admin_order_meta($order){
  46.     echo '<p><strong>'.__('Business Phone').':</strong> ' . get_post_meta( $order->id, 'Business Phone', true ) . '</p>';
  47. }
RAW Paste Data