Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add phone # fields
- add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
- function custom_override_checkout_fields( $fields ) {
- $fields['billing']['cell_phone'] = array(
- 'label' => __('Cell Phone', 'woocommerce'),
- 'placeholder' => _x('', 'placeholder', 'woocommerce'),
- 'required' => false,
- 'class' => array('form-row-first'),
- 'clear' => false
- );
- $fields['billing']['biz_phone'] = array(
- 'label' => __('Business Phone', 'woocommerce'),
- 'placeholder' => _x('', 'placeholder', 'woocommerce'),
- 'required' => false,
- 'class' => array('form-row-last'),
- 'clear' => true
- );
- return $fields;
- }
- // Update the order meta with field value for cell phone
- add_action( 'woocommerce_checkout_update_order_meta', 'cell_phone_field_update_order_meta' );
- function cell_phone_field_update_order_meta( $order_id ) {
- if ( ! empty( $_POST['cell_phone'] ) ) {
- update_post_meta( $order_id, 'Cell Phone', sanitize_text_field( $_POST['cell_phone'] ) );
- }
- }
- // Update the order meta with field value for biz phone
- add_action( 'woocommerce_checkout_update_order_meta', 'biz_phone_field_update_order_meta' );
- function biz_phone_field_update_order_meta( $order_id ) {
- if ( ! empty( $_POST['biz_phone'] ) ) {
- update_post_meta( $order_id, 'Business Phone', sanitize_text_field( $_POST['biz_phone'] ) );
- }
- }
- // Display cell phone # on the order edit page
- add_action( 'woocommerce_admin_order_data_after_billing_address', 'cell_phone_field_display_admin_order_meta', 10, 1 );
- function cell_phone_field_display_admin_order_meta($order){
- echo '<p><strong>'.__('Cell Phone').':</strong> ' . get_post_meta( $order->id, 'Cell Phone', true ) . '</p>';
- }
- // Display biz phone # on the order edit page
- add_action( 'woocommerce_admin_order_data_after_billing_address', 'biz_phone_field_display_admin_order_meta', 10, 1 );
- function biz_phone_field_display_admin_order_meta($order){
- echo '<p><strong>'.__('Business Phone').':</strong> ' . get_post_meta( $order->id, 'Business Phone', true ) . '</p>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement